Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#85 2012-08-04 13:29:46

etc
Developer
Registered: 2010-11-11
Posts: 5,219
Website GitHub

Re: etc_query: all things Textpattern

Hi Jonathan, as soon as I get a decent internet connection (but this could take 3 weeks)! I couldn’t do better than progre55 on multi-select, but will try to find another example of conditional txp tag construction.

Offline

#86 2012-08-07 19:21:46

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,310

Re: etc_query: all things Textpattern

etc wrote (in adi_gps):

Everything between the problem statement and the final 4-5 posts can be safely trashed, I think.

progre55 linked right amidst one of these posts from his tutorial, so I thought it’s better to leave the thread readable and link from before the cluster to its end.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#87 2012-09-09 13:59:05

etc
Developer
Registered: 2010-11-11
Posts: 5,219
Website GitHub

Re: etc_query: all things Textpattern

New version is out, with enhanced replace attribute for easy nodes insertion, more convenient syntax and new name attribute, to assign the output to a variable. Ready to go on the admin side if needed.

Many thanks to all who have tested it. Everything seems to work fine, so let it be version 1.0.

Offline

#88 2012-09-18 20:59:25

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: etc_query: all things Textpattern

I’m posting here because the comment form at TXPTips (on the archive tree with article counts tip) is marking my comment as spam:

Nice tip!
One thing: on the etc_query line, I’ve had to remove the $[ and the ]$.
If not, I would get the output as this:

2012 ([$7$])

Not sure why…


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#89 2012-09-18 21:16:14

etc
Developer
Registered: 2010-11-11
Posts: 5,219
Website GitHub

Re: etc_query: all things Textpattern

Thank you for the report, Julian. The etc_query syntax has a little changed since, these $[]$ are not needed anymore.

Offline

#90 2012-09-18 21:39:55

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: etc_query: all things Textpattern

You are welcome. Thank you for this crazy plugin.
Here’s another one (while trying to wrap my head around this plugin, its syntax and XPath syntax):

Following the tip (the one linked above), I’ve tried putting the wraptag="ul" directly into txp:article_custom (and removed it from txp:etc_query), while keeping query="li".
But then, it didn’t work… why?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#91 2012-09-18 21:50:35

etc
Developer
Registered: 2010-11-11
Posts: 5,219
Website GitHub

Re: etc_query: all things Textpattern

Because you feed etc_query with <ul><li>...</li><li>...</li></ul>, so you should query for ul/li. But then you will get <li>...</li><li>...</li> as output. I think in this case

<txp:etc_query data='<txp:variable name="archive" />' replace="ul/li//span={count(..//li[@class='article'])}"/>

could work, but have not tried it and it does not, there must be a good reason.

Last edited by etc (2012-09-18 21:54:27)

Offline

#92 2012-09-18 22:05:47

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: etc_query: all things Textpattern

Thanks for the prompt reply. The original code Just Works, and I’m happy with that, at least, by now :)

I’m also thinking about caching the output with aks_cache.
But, unless I’m missing something (not so) obvious, it seems that in this particular tip, there are two ways to get the benefits of caching the output:

  • one is by wrapping the whole tip code in txp:aks_cache (but losing the ability of reusing the txp:variable).
  • the second one is by using two aks_cache blocks: one cache block wrapping article_custom (but inside the txp:variable) and saving the DB queries, and one cache block wrapping etc_query, saving some processing… This second approach seems more correct.

(if I only wrap the tag generating the output (etc_query, in this case), article_custom will be running on each request anyway)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#93 2012-09-18 22:08:19

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: etc_query: all things Textpattern

etc wrote:

<txp:etc_query data='<txp:variable name="archive" />' replace="ul/li//span={count(..//li[@class='article'])}"/>

could work, but have not tried it and it does not, there must be a good reason.

I can confirm it works :)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#94 2012-09-18 22:13:16

etc
Developer
Registered: 2010-11-11
Posts: 5,219
Website GitHub

Re: etc_query: all things Textpattern

From what I have measured for ~200 articles, etc_query will run ~50 times faster than article_custom.

Edit: my laptop hdd is crappy, still the ratio is 1/25 on a true server. So you should definitely cache article_custom. Caching etc_query is worth it too: though you will hardly see the difference between 0.007s and 0.0007s, it will save some runtime memory.

Last edited by etc (2012-09-19 08:37:31)

Offline

#95 2012-09-19 08:42:10

etc
Developer
Registered: 2010-11-11
Posts: 5,219
Website GitHub

Re: etc_query: all things Textpattern

maniqui wrote:

I can confirm it works :)

I am always surprised with it :) For cleaner markup, you can remove spans from article_custom and inject them afterwards with etc_query:

<txp:etc_query data='<txp:variable name="archive" />' replace="ul//ul^=<span>({count(..//li[@class='article'])})</span>" />

Offline

#96 2012-09-21 13:47:59

Zanza
Plugin Author
Registered: 2005-08-18
Posts: 699
Website

Re: etc_query: all things Textpattern

Coming from another thread (smd_xml), I tried your plugin. While the examples in the help do work, it seems like I’m unable to parse anything from a youtube feed. Example:

<txp:etc_query url="http://gdata.youtube.com/feeds/api/users/boscartoon/playlists?v=2"
  markup="xml"
  query="feed/title"
  wraptag="ul"
  label="News from Youtube" labeltag="h4">
    </li>{title?}</li>
</txp:etc_query>

Not even the label tag appears. Tried different syntax and queries, with no luck. Apparently I’m missing something obvious, but what?
Feel free to test the feed in the code, if you find the time.

Thank you!

Last edited by Zanza (2012-09-21 14:11:53)

Offline

Board footer

Powered by FluxBB