Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#46 2008-11-04 23:47:37

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: an attribute named "empty"

Hi Els, this is odd because it works for me. What rev of TXP are you using? There was a bug fix at r2938.

For example, if I set this up in an article form:

<txp:if_variable name="gizmo">
EXISTS
</txp:if_variable>
<txp:if_variable name="gizmo" value="">
EMPTY
</txp:if_variable>
<txp:if_variable name="gizmo" value="yup">
MATCHES
</txp:if_variable>

and then, above it I add this:

<txp:variable name="gizmo" />

I get nothing.

With this:

<txp:variable name="gizmo" value="els" />

I get EXISTS.

With:

<txp:variable name="gizmo" value="" />

I get EXISTS EMPTY.

And with:

<txp:variable name="gizmo" value="yup" />

I get EXISTS MATCHES

As expected. Your results imply something’s going wrong somewhere… hmmmm..

Last edited by Bloke (2008-11-04 23:47:54)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Online

#47 2008-11-05 00:13:45

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: an attribute named "empty"

Hi Stef, thanks for looking! I’m using revision 2987. I still don’t understand why it doesn’t work for me.

I’ve got 3 file categories: en, nl and pt. There are 2 files in category nl, 1 in en, and 0 in pt. I’ve got a file form named ‘file_cat’ with only this: <txp:file_download_category />.

This is how I set the variable’s value, it takes the language code from the page I’m on for the category attribute’s value:

<txp:variable name="file_count" value='<txp:file_download_list form="file_cat" category="<txp:l10n_get_lang type="short" />" />' />

Next, to check, I’ve got this:

<p>output: <txp:variable name="file_count" /></p>

It gives the correct output on every page!

Then:

<txp:if_variable name="file_count" value="">
<p>empty!</p>
<txp:else />
<p>There are files in category <txp:l10n_get_lang type="short" />!</p>
</txp:if_variable>

Have a look here (just below the google map) and look at the other two language pages. (Site is in debugging mode.)

Offline

#48 2008-11-05 00:54:29

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: an attribute named "empty"

Bizarre! I think it’s a quoting issue.

Since I don’t have any files on my site, I’m using links instead. Using a similar setup to yours, I have an article form with the txp:variable/if_variable tags in it. I have a form called lc that just returns the name of the <txp:link_category />.

For reference, there are the three standard links in the ‘textpattern’ link category. I set up another link category called ‘photo’ to which I assigned no links.

With this in my article form:

<txp:variable name="gizmo" value='<txp:linklist category="textpattern" form="lc" />' />

SET TO: <txp:variable name="gizmo" />

<txp:if_variable name="gizmo">
EXISTS
</txp:if_variable>

<txp:if_variable name="gizmo" value="">
EMPTY
</txp:if_variable>

<txp:if_variable name="gizmo" value="rr">
MATCHES
</txp:if_variable>

I see this output: SET TO: textpatterntextpatterntextpattern EXISTS

Excatly as expected. Changing the first line to:

<txp:variable name="gizmo" value='<txp:linklist category="photo" form="lc" />' />

I see: SET TO: EXISTS EMPTY

Which is again what I’d expect. However, taking it one stage further and nesting a third tag like you have done makes it interesting. I went into my article and put the name of my desired link category into custom1, then used this in the first line of my article form above:

<txp:variable name="gizmo" value='<txp:linklist category="<txp:custom_field name="custom1" />" form="lc" />' />

(double quotes around the category name that houses the custom filed call)

I saw: SET TO: textpatterntextpatterntextpattern EXISTS as expected.

But changing custom1 in my article to read photo caused this output: SET TO: EXISTS

Bogus! I expected to see EMPTY as well (as you are expecting, too ;-) So I changed the quotes to single quotes, viz:

<txp:variable name="gizmo" value='<txp:linklist category='<txp:custom_field name="custom1" />' form="lc" />' />

Now I just get SET TO: no matter what I put in custom1. Faffing around with random pairs of single and double quotes around different parts of the expression always yields either nothing (the SET TO: which I think is an error case) or the EXISTS case. But never EMPTY.

So you are totally correct in that it is not behaving how we expect when nesting multiple calls.

I know there’s a difference between single and double quotes in the new parser so this is probably because the parser is crying and terminating a set of quotes too early. But I’ve no idea how to debug it and find out what combination of single and double quotes would render the result we expect. More fiddling required, methinx :-(

Unless there’s another way to rewrite it with only a single level of nesting…?

Last edited by Bloke (2008-11-05 00:58:58)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Online

#49 2008-11-05 01:07:43

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: an attribute named "empty"

Surely I’m wrong but can’t it depend upon how you have nested double quotes in your <txp:variable />?

this:

<txp:variable name="file_count" value='<txp:file_download_list form="file_cat" category="<txp:l10n_get_lang type="short" />" />' />

shouldn’t be this?:

<txp:variable name="file_count" value='<txp:file_download_list form="file_cat" category="<txp:l10n_get_lang type='short' />" />' />

Note the single quotes around the attribute “short”

edit: Oops, Bloke was faster and more precise

Last edited by redbot (2008-11-05 01:09:26)

Offline

#50 2008-11-05 01:12:40

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: an attribute named "empty"

Phew… am I glad that it’s not just me… ;)

Your findings are exactly like mine. I started with single quotes around the third nested tag, and later on changed it to double quotes. Because the output of the variable tag is correct, I didn’t think that the multi-level nesting would be the problem… but I’m not sure of course.

Unless there’s another way to rewrite it with only a single level of nesting…?

Oh, I can always find another way to do it. I can put the file download code in the articles, I’ll only have to remember to add it to the pt article whenever I’m going to add files to that category as well.
But I really liked my piece of code ;) and it would have been fully automated that way. Oh well, we can’t have everything I guess… ;) (and there is always chh_if_data)

Thanks very much for confirming my sanity!

Offline

#51 2008-11-05 01:16:07

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: an attribute named "empty"

redbot wrote:

Note the single quotes around the attribute “short”

I even tried it that way, but it doesn’t get parsed right if you do that, in the tag trace it looked like this:

[SQL (0,000139951705933): select *,`l10n_description_en_gb` as `description` from txp_file where 1=1 and category IN ('<txp:l10n_get_lang type=\'short\' />') and status = '4' order by filename asc limit 0, 10]

Offline

#52 2008-11-05 01:20:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: an attribute named "empty"

redbot wrote:

Note the single quotes around the attribute “short”

Yeah, I thought that would be it as well. I’ve tried all these permutations so far and have had not had the “right” answer yet:

<txp:variable name="file_count" value='<txp:file_download_list form="file_cat" category="<txp:l10n_get_lang type="short" />" />' />
<txp:variable name="file_count" value="<txp:file_download_list form="file_cat" category="<txp:l10n_get_lang type="short" />" />" />
<txp:variable name="file_count" value='<txp:file_download_list form="file_cat" category='<txp:l10n_get_lang type="short" />' />' />
<txp:variable name="file_count" value='<txp:file_download_list form="file_cat" category="<txp:l10n_get_lang type='short' />" />' />
<txp:variable name="file_count" value="<txp:file_download_list form="file_cat" category="<txp:l10n_get_lang type='short' />" />" />
<txp:variable name="file_count" value="<txp:file_download_list form="file_cat" category='<txp:l10n_get_lang type="short" />' />" />

I got bored of trying after that lot :-P

Must be some scientific way of proving this or working out the correct single/double quote syntax to render the correct result. I’ve even tried approaching it as if I was the parser, going in as far as I can and successively working out — reverse-Polish stylie — but my brain went soggy.

Last edited by Bloke (2008-11-05 01:21:46)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Online

#53 2008-11-05 01:31:41

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: an attribute named "empty"

Bloke wrote:

I’ve even tried approaching it as if I was the parser, going in as far as I can

Sounds a bit like Being John Malkovich… seriously, don’t go in too deep or you’ll at least have nasty dreams tonight.
Maybe one of the devs can shed some light on this. Tomorrow. Thanks again and sleep well :)

Offline

#54 2008-11-05 12:38:32

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: an attribute named "empty"

<txp:variable name="file_count" value='<txp:file_download_list form="file_cat" category=''<txp:l10n_get_lang type="short" />'' />' />

escaping of quotes in 4.0.7 attribute values is done by using 2 consecutive quotes.

Offline

#55 2008-11-05 12:57:27

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: an attribute named "empty"

ruud wrote:

escaping of quotes in 4.0.7 attribute values is done by using 2 consecutive quotes.

Awesome, it works poifickly!

Thanks for clearing that up. I’d have been there all day figuring that out on my own. Must have missed that bit in your parser write-up doc.

Last edited by Bloke (2008-11-05 12:58:12)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Online

#56 2008-11-05 17:21:46

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: an attribute named "empty"

Perfect! Thanks Ruud! Great that it can be done after all, now anything seems possible… :)

Offline

#57 2008-12-24 14:19:58

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

Re: an attribute named "empty"

Look at this tip on TXP Tips.
I think it’s an interesting (and simple) case for dissection.

For the sake of brevity and clarity, I will rewrite it using container tags instead of forms, and also omitting some chunks of code that aren’t essential for this dissection.

<txp:section_list class="" break=""
wraptag="dl" sections="about,services,case-studies,contact">
  <txp:if_section name='<txp:section />'>
    <txp:article_custom section='<txp:section />' form="nav.build.link" />
  </txp:if_section>
</txp:section_list>

The important part (where at first I thought there was a mistake, but now I think it’s a great example on how this thing works) is this:

  <txp:if_section name='<txp:section />'>
  <txp:article_custom section='<txp:section />' form="nav.build.link" />
  </txp:if_section>

As wet clearly explained, some tags (txp:section, for example) are “tag context sensitive”.
So, the above chunk of code, read in plain simple english:

If section for current URL is equal to section currently iterated (txp:section) on this section list, then output a list of articles for this current iterated section.

Great! :D

BTW: I think that when 4.0.7 was out, there was a bug, and txp:section value wasn’t reverted back to its corresponding value after leaving the iteration. Where’s the patch for that? (can’t find it)

Last edited by maniqui (2008-12-26 20:35:36)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#58 2008-12-26 20:32:05

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

Re: an attribute named "empty"

maniqui

Nice explanation, thanks. It is certainly very cool what’s possible in 4.0.7 now. Not just in terms of new tags, but some severely awesome enhancements “under the hood” that enables stuff like this. And searching arbitrary columns. And time/event-based articles. And…

I think that when 4.0.7 was out, there was a bug, and txp:section value wasn’t reverted back to its corresponding value after leaving the iteration. Where’s the patch for that? (can’t find it)

r3037 ?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Online

#59 2008-12-26 20:40:23

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

Re: an attribute named "empty"

Thanks, Bloke, glad you liked it.

I fixed an error on the “plain english” version, I don’t know why I typed txp:title instead of txp:section.

Thanks for pointing to the fixed version of taghandlers.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB