Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#37 2008-08-17 07:27:04

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: an attribute named "empty"

maniqui wrote:

Thanks again to devs for all the

…fish?

Offline

#38 2008-08-17 07:58:42

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

Re: an attribute named "empty"

New tags and parsing features don’t make the learning curve steeper, only longer; They just allow you to continue learning new things if you need them. Users that are currently at the end of the learning curve can choose in 4.0.7: use what they already know… or learn more.

The difference between basic and advanced tags differs for all users. Some people find if_different easy to use, while others fail to grasp how it’s supposed to work.

Offline

#39 2008-08-17 12:16:54

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

Re: an attribute named "empty"

maniqui.
thanks for the kind words, I agree with you (even if you seem to agree with me).

ruud wrote:

New tags and parsing features don’t make the learning curve steeper, only longer; They just allow you to continue learning new things if you need them. Users that are currently at the end of the learning curve can choose in 4.0.7: use what they already know… or learn more.

I have a slightly different approach here. As I said before, I was referring only to documentation, with particular regard to novice users. I like all the new features and I’m sure they will prove to be very useful (to begin with the new tag parser). Nonetheless I’m convinced that a clear distinction between basic and advanced tags can help from an “usability” point of view and can contribute to a smoother learning curve.

The difference between basic and advanced tags differs for all users. Some people find if_different easy to use, while others fail to grasp how it’s supposed to work.

That’s true. But if I have to learn a programming manual I prefer to learn one which makes it clear from the index how it is structured, which are the basic chapters and the advanced ones.
Clearly the same content can be “presented” quite differently (all in all we are talking about documentation, not a novel) depending on the target audience so probably our different views on the matter are due to different assumptions on which should be the main target audience. You seem to have in mind a more advanced audience while I think novice users should be privileged (and this should not harm the more advanced users so much).

Following the same logic I continue to think an hypothetic “if_data” tag could happily coexist with the txp:variable” tag and it should be into the core.

Ok now I will stop complaining as I realize I went totally off topic now and all in all these are not crucial problems.

maniqui wrote:

Thanks again to devs for all the

Ouch! it’s happened aga

Last edited by redbot (2008-08-17 12:23:05)

Offline

#40 2008-08-17 14:09:13

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: an attribute named "empty"

redbot wrote:

Ouch! it’s happened aga

…aga khan?

Last edited by Gocom (2008-08-17 14:09:50)

Offline

#41 2008-10-30 15:37:29

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

Re: an attribute named "empty"

wet wrote:

Intended behaviour is:

  1. <txp:variable name="foo" /> returns the variable’s value.
  2. <txp:variable name="foo" value="" /> erases the variable’s value. The variable still exists, though empty.
  3. <txp:variable name="foo" value="bar" /> sets the variable’s value. Basically this is the same as #2.
  4. <txp:if_variable name="foo"> tests for the existence.
  5. <txp:if_variable name="foo" value="bar"> tests for the value, and therefore also for the existence.

I’m sure I’m overlooking or misunderstanding something, but I just can’t figure out why my following code doesn’t work:

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

<txp:if_variable name="file_count">

<h3>Some Header</h3>

<txp:file_download_list category='<txp:l10n_get_lang type="short" />' wraptag="ul" break="li" />

</txp:if_variable>

I’m checking if there are files in a given category in order to only display the header if there are files. There are in fact two files, but the condition returns false. This is the relevant part of the tag trace:

	<txp:file_download_list category='<txp:l10n_get_lang type="short" />' />
		[attribute 'category']
		<txp:l10n_get_lang type="short" />
		[/attribute]
		[SQL (0,000148057937622): select *,`l10n_description_nl_nl` as `description` from txp_file where 1=1 and category IN ('nl') and status = '4' order by filename asc limit 0, 10]
		[SQL (8,48770141602E-5): select Form from txp_form where name='files']
		[Module: files]
		<txp:file_download_link>
			<txp:file_download_description />
		</txp:file_download_link>
		[Module: files]
		<txp:file_download_link>
			<txp:file_download_description />
		</txp:file_download_link>
	<txp:if_variable name="file_count">
		[<txp:if_variable name="file_count">: false]
	</txp:if_variable>
[ ~~~ secondpass ~~~ ]
<txp:variable name="file_count" value='<a href="http://mlptest.casadonamaria.nl/file_download/1/route_lissabon_vilacova_nederlands.pdf">
Van Lissabon naar Vila Cova de Alva
</a>
<a href="http://mlptest.casadonamaria.nl/file_download/2/route_porto_vilacova_nederlands.pdf">
Van Porto naar Vila Cova de Alva
</a>' />
 -->

It looks like the variable’s value is set, but after [ ~~~ secondpass ~~~ ] (whatever that may be, but I’m guessing that nothing is supposed to happen after it?)

Offline

#42 2008-10-31 02:21:04

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: an attribute named "empty"

Try this:

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

Offline

#43 2008-10-31 16:16:29

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

Re: an attribute named "empty"

Thanks Robert, but now it always returns ‘true’… Maybe it’s my setup? I’m using the MLP Pack and languages are nl, en, pt. I created identical file categories: ‘nl’, ‘en’, ‘pt’. This is the tag trace of a pt page, where the condition should return false, because there are no files in category ‘pt’:

	<txp:variable name="file_count" value='<txp:file_download_list category="<txp:l10n_get_lang type="short" />" />' />
		[attribute 'value']
		<txp:l10n_get_lang type="short" />
		[/attribute]
	<txp:if_variable name="file_count">
		[<txp:if_variable name="file_count">: true]
		<txp:file_download_list category='<txp:l10n_get_lang type="short" />' wraptag="ul" break="li" />
			[attribute 'category']
			<txp:l10n_get_lang type="short" />
			[/attribute]
			[SQL (0,000139951705933): select *,`l10n_description_pt_pt` as `description` from txp_file where 1=1 and category IN ('pt') and status = '4' order by filename asc limit 0, 10]
	</txp:if_variable>
[ ~~~ secondpass ~~~ ]
 -->

Form:

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

<txp:if_variable name="file_count">

<h3>Downloads</h3>

<txp:file_download_list category='<txp:l10n_get_lang type="short" />' wraptag="ul" break="li" />

</txp:if_variable>

HTML output:

<h3>Downloads</h3>

‘files’ form (if that matters):

<txp:file_download_link>
<txp:file_download_description />
</txp:file_download_link>

Last edited by els (2008-10-31 16:25:13)

Offline

#44 2008-11-03 21:41:34

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

Re: an attribute named "empty"

(Apologies for bumping…)

Of course I can use other ways to do this so I don’t really need this code to work, but what I do need is to test my understanding of the variable tag’s workings.

So, does my code above make any sense at all? Or where do I go wrong?

Offline

#45 2008-11-04 22:58:51

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

Re: an attribute named "empty"

<txp:variable name="foo" value="" /> erases the variable’s value. The variable still exists, though empty.

<txp:if_variable name="foo"> tests for the existence.

So it always returns true, once the variable’s value has been set, doesn’t matter if it’s empty or not, right?

<txp:if_variable name="foo" value="bar"> tests for the value

But how do I test for an empty value? <txp:if_variable name="foo" value=""> always returns false…

Sigh.

(I don’t mind if I don’t get any replies, honest; I’ll just go on talking to myself until I figure it out…)

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
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.

Txp Builders – finely-crafted code, design and Txp

Offline

#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: 11,448
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.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB