Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

etc
Developer
Registered: 2010-11-11
Posts: 5,689
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,689
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,689
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

#97 2012-09-21 14:05:07

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

Re: etc_query: all things Textpattern

Zanza wrote:

</li>{title?}</li>

Hi Zanza,
simply proofreading your code: Might it be the closing </li> at the beginning?


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

Offline

#98 2012-09-21 14:10:04

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

Re: etc_query: all things Textpattern

Ops! Thank you, Uli, well spot! But no, it doesn’t change. Not even the h4 tag is displayed… :(

Offline

#99 2012-09-21 15:12:58

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

Re: etc_query: all things Textpattern

That’s weird. If you replace markup="xml" by markup="html", it works, but that’s weird:

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

There must be a namespacing issue I don’t understand, or I have introduced some bug in the latest version. Will check it, sorry.

Offline

#100 2012-09-21 15:42:00

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

Re: etc_query: all things Textpattern

Thank you, it actually works: I can extract any node, as long as it isn’t “namespace-d”.

That is: I can’t extract media:group tag, or yt:countId, etc. Maybe there is a specific syntax for those?

Offline

#101 2012-09-21 15:51:01

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

Re: etc_query: all things Textpattern

That’s the drawback of importing them as html: they become group and countId (can you try?). Importing as xml works too if I put

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

Help’s example feed works fine, so there must be no bug, I just have to learn xml.

Offline

#102 2012-09-21 16:14:21

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

Re: etc_query: all things Textpattern

group and userId doesn’t work. I’ll try the new syntax with markup xml and report back, thanks.

Offline

#103 2012-09-21 16:21:59

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

Re: etc_query: all things Textpattern

They go lowercase, sorry. This works for me:

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

Two rows are retrieved, you’ll have to target with more precision.

Offline

#104 2012-09-21 16:33:03

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

Re: etc_query: all things Textpattern

Genious! Thank you, you’ve been incredibly helpful!

Offline

#105 2012-09-21 16:49:48

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

Re: etc_query: all things Textpattern

Fine! Thanks for testing and stay tuned: I am already patching etc_query with namespaces.

Edit: could you keep the feed online for some hours, for testing? Many thanks.

Last edited by etc (2012-09-21 16:52:15)

Offline

Board footer

Powered by FluxBB