Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
attribute-less [txp:if_custom_field] conditional no longer works
At some point I was using something like the following, to test for the existence (or not) of any custom fields associated with an article.
<txp:if_custom_field><div id="details"/></txp:if_custom_field>
<txp:if_custom_field name="my cf name">
<p>a value called <txp:custom_field name="my cf name" /></p>
</txp:if_custom_field>
<txp:if_custom_field></div></txp:if_custom_field>
So if there are no custom fields for this article nothing appears, if there are, it displays a div with some text and the contents of the custom field.
This no longer seems to work, resulting in nothing being displayed regardless of whether custom fields are present or not.
I’m using super recent revs of 4.04
Any ideas?
Offline
#2 2007-02-09 22:11:41
- zem
- Developer Emeritus

- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: attribute-less [txp:if_custom_field] conditional no longer works
I don’t think that ever worked quite like you think. If you don’t specify a name attribute, if_custom_field checks for a custom_1 value.
The only recent change was to add some error checking, and make the name attribute case-insensitive.
Alex
Offline
Re: attribute-less [txp:if_custom_field] conditional no longer works
well crap! I guess I must have not have had any articles accessing that form before that were without custom fields.
Any way to test for existence of any custom fields in an article?
Offline
#4 2007-02-09 22:43:03
- zem
- Developer Emeritus

- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: attribute-less [txp:if_custom_field] conditional no longer works
Not that I know of with built-in tags. A plugin could do it easily.
Alex
Offline
Re: attribute-less [txp:if_custom_field] conditional no longer works
Oh, estupido! [smacks self on head] chh_if_data to the rescue…
<txp:chh_if_data>
<div class="details">
<txp:if_custom_field name="my cf name">
<txp:custom_field name="my cf name"/>
</txp:if_custom_field>
</div>
<txp:else/>
nothing to see here...
</txp:chh_if_data>
This should work I suppose…
Last edited by mrdale (2007-02-09 23:22:20)
Offline
#6 2007-02-09 23:39:21
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: attribute-less [txp:if_custom_field] conditional no longer works
What’s the difference with
<txp:if_custom_field name="my cf name">
<div class="details">
<txp:custom_field name="my cf name"/>
</div>
<txp:else/>
nothing to see here...
</txp:if_custom_field>
?
Offline
Re: attribute-less [txp:if_custom_field] conditional no longer works
>els
What’s the difference with…
I simplified my example for illustrative purposes.
What I commonly need to acheive is a situation where if there are custom fields, wrap them each in p-tags with some explanatory text and wrap those in a div. If there are no custom fields, I don’t want to see the div.
So I guess the containing div is the difference…
Last edited by mrdale (2007-02-10 00:47:41)
Offline
#8 2007-02-10 14:18:44
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: attribute-less [txp:if_custom_field] conditional no longer works
Still don’t get it, sorry ;) If_custom_field already checks if the custom field has a value, why would you need chh_if_data?
Offline
Re: attribute-less [txp:if_custom_field] conditional no longer works
OK, I’ll do a better job of explaining…
You only want a (styled) div to appear if there are custom fields assigned to an article to fill it. Otherwise you end up with an empty styled div.
Without any machinations with chh_if_data the div will appear regardless of whether there is content to fill it.
Offline
Re: attribute-less [txp:if_custom_field] conditional no longer works
As Els, I must admit I don’t get it either
<txp:if_custom_field name="my cf name">
<div class="details">
<txp:custom_field name="my cf name"/>
</div>
</txp:if_custom_field>
That should work too. Or are we wrong?
Take a look at this TextBook entries for txp:if_custom_field:
Example 2: Display contents of custom fields and create behavior if field has no content
Example 4: Display content if a custom field contains data or display something else if it doesn’t
Offline
#11 2007-02-10 20:08:15
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: attribute-less [txp:if_custom_field] conditional no longer works
He means if an article has custom fields of any kind, not checking for specific fields. Read Alex’s comment.
Offline