Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#229 2015-05-20 12:50:35
Re: etc_query: all things Textpattern
Of course you’re right! Textpattern’s use of line breaks in code always trips me up – I like to have the line breaks in there to improve readability, but then it sometimes causes other things to break.
And my real problem is learning about all of the cool things that etc_query
can do.
Offline
#230 2015-05-21 09:10:22
Re: etc_query: all things Textpattern
aslsw66 wrote #290947:
And my real problem is learning about all of the cool things that
etc_query
can do.
Thanks. It’s a tool, so it does only what you tell it to do. In your example
<txp:etc_query url="ftp://ftp2.bom.gov.au/anon/gen/fwo/IDN10035.xml" markup="xml" query="//text[@type='fire_danger']">
{?}
</txp:etc_query>
you tell it to download the XML file from ftp://ftp2.bom.gov.au/anon/gen/fwo/IDN10035.xml
, look for all <text type="fire_danger" ... />
tags, and output their value ({?}
), with linebreaks before and after it. If no such tag exists, etc_query
will output <txp:else />
“false” part (if present).
Online
#231 2015-07-18 10:20:49
Online
#232 2015-09-11 09:15:01
Re: etc_query: all things Textpattern
Hi, I’m using the following code in an article form to pull the first quote from articles body :
(I know smd_pullquotes
but I want to use etc_query
which I already use on the project.)
<txp:etc_query data="{?body}" query="(//blockquote)[1]" wraptag="blockquote">
{p}{cite}
</txp:etc_query>
However, I would like to display only articles which contain blockquotes;
Help welcome, I’m not good with etc_query
already…
Thanks!
Last edited by NicolasGraph (2015-09-11 09:23:21)
Offline
#233 2015-09-11 09:40:46
Re: etc_query: all things Textpattern
NicolasGraph wrote #294722:
Help welcome, I’m not good with
etc_query
already…
Hi Nicolas, me too, I’m afraid! :) Your code should already not display anything for articles without blockquotes, so I guess you want to retrieve from db only the articles containing blockquotes. I’m not sure you can do it with <txp:article(_custom) />
, but with etc_query
v.1.3 this should work:
<txp:etc_query data="Body_html LIKE '%</blockquote>%'" markup="db" populate="article">
<txp:etc_query data='<txp:body />' specials="" query="//blockquote[1]" limit="1" wraptag="blockquote">
{{p}}{{cite}}
</txp:etc_query>
</txp:etc_query>
As you see, I have added limit="1"
attribute, otherwise it could output multiple blockquotes if they had different parents. Note also double {{}}
braces, to tell the external etc_query
that they belong to the internal one.
Tell me if it helps (quickly tested). You can add AND Section='some_section' ORDER BY Posted DESC LIMIT 10
and so on to data
attribute if needed.
Last edited by etc (2015-09-11 16:17:33)
Online
#234 2015-09-11 10:01:34
Re: etc_query: all things Textpattern
etc wrote #294723:
Tell me if it helps (quickly tested). You can add
AND Section='some_section'
,ORDER BY Posted DESC LIMIT 10
and so on todata
attribute if needed.
Thanks Oleg, you understood well what I’m trying to achieve but the limit attribute doesn’t work for me now.
Last edited by NicolasGraph (2015-09-11 10:04:03)
Offline
#235 2015-09-11 16:24:26
Re: etc_query: all things Textpattern
NicolasGraph wrote #294725:
the limit attribute doesn’t work for me now.
Which one? There is no comma in AND Section='some_section' ORDER BY Posted DESC LIMIT 10
, sorry. It should work, unless some of the retrieved articles contain <txp:article_custom />
(it sticks on this article otherwise, patch in progress). And you shouldn’t put this code inside an article that contains <blockquote />
itself, or you’ll enter an infinite loop. Replacing data='<txp:body />' specials=""
with data="{{?body}}" specials="data"
should fix it though.
Online
#236 2015-09-12 08:29:28
Re: etc_query: all things Textpattern
etc wrote #294732:
Which one?
Sorry, I talked about the limit attribute above…
As you see, I have added limit=“1” attribute, otherwise it could output multiple blockquotes if they had different parents.
It outputs multiple blockquotes anyway…
Last edited by NicolasGraph (2015-09-12 08:29:51)
Offline
#237 2015-09-12 08:54:03
Re: etc_query: all things Textpattern
Ah, that’s interesting, you mean multiple blockquotes from the same article? Unless you have blockquotes within blockquotes… mind posting the html body of the concerned article?
Online
#238 2015-09-12 09:12:04
Re: etc_query: all things Textpattern
etc wrote #294743:
Ah, that’s interesting, you mean multiple blockquotes from the same article? Unless you have blockquotes within blockquotes… mind posting the html body of the concerned article?
No, in fact it displays only the first blockquote of the concerned articles bodies, but I can’t limit them to show only one (or whatever) blockquote like I could do with the following code if every articles would contain blockquotes…
<txp:article_custom limit="1" sort="rand()">
<txp:etc_query data="{?body}" query="(//blockquote)[1]" wraptag="blockquote">
{p}{cite}
</txp:etc_query>
</txp:article_custom>
The only wrong thing with this code is that it displays nothing if the article doesn’t contain a blockquote.
Last edited by NicolasGraph (2015-09-12 09:13:48)
Offline
#239 2015-09-12 09:16:50
Re: etc_query: all things Textpattern
Ah, ok, then doesn’t this work as intended?
<txp:etc_query data="Body_html LIKE '%</blockquote>%' ORDER BY RAND() LIMIT 1" markup="db" populate="article">
<txp:etc_query data='<txp:body />' specials="" query="//blockquote[1]" limit="1" wraptag="blockquote">
{{p}}{{cite}}
</txp:etc_query>
</txp:etc_query>
The external etc_query
plays the role of article_custom
here.
Online
#240 2015-09-12 09:23:23
Re: etc_query: all things Textpattern
etc wrote #294745:
Ah, ok, then doesn’t this work as intended?
It does! Thanks, I found the solution just before to read your reply… Sorry, I understand quickly but I need a lot of explanations! :-/
Offline