Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-01-11 11:36:23

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

@variable@ container tag when tag is empty

I was surprised to discover that this:

<txp:variable name="test"></txp:variable>

is not equivalent to this:

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

It is, rather, equivalent to this:

<txp:variable name="test" />

i.e., it doesn’t actually assign anything, it just returns the variable.

Various Txp tips include this kind of construct:

<txp:variable name="has_articles"><txp:article limit="1">1</txp:article></txp:variable>

which will produce unexpected results when there are no articles. If this is an attempt to initialize the variable, it will throw a tag error. If the variable already exists, this will simply return its value. You should use single-tag mode to assign variables unless you are certain the container will never be empty. I don’t know if this is intentional behavior, but it is counter-intuitive. Changing it is trivial:

$HeadURL: https://textpattern.googlecode.com/svn/releases/4.3.0/source/textpattern/publish/taghandlers.php $
$LastChangedRevision: 3443 $
...
4501	if (!isset($atts['value']) and is_null($thing))

Code is topiary

Offline

#2 2011-01-11 11:42:28

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: @variable@ container tag when tag is empty

I added a note to the Wiki entry.


Code is topiary

Offline

#3 2011-01-11 13:38:55

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

Re: @variable@ container tag when tag is empty

This looks like an oversight.

Offline

#4 2011-01-12 12:01:06

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

Re: @variable@ container tag when tag is empty

Fixed in r3471. Thanks, Jeff.

Offline

Board footer

Powered by FluxBB