Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
If a named custom field has something in it, output what's in it
Hey.
I’m using if_custom_field
for the first time and I’ve stumbled across what might be a bug, but is more likely to be something I’m missing (e.g., my fault).
I want to check an article’s custom fields for content, and if it has some I want to output it. Here’s what I’m using:
<txp:if_custom_field name=“mp3-media-url” />
<div class=“btn-group”>
<a class=“btn” href=”<txp:custom_field name=‘mp3-media-url’ />”>Get MP3</a>
</div>
</txp:if_custom_field>
I have two test articles, one with the mp3-media-url
field set with an MP3 URL, and the other article has an empty mp3-media-url
. Both of these articles, when rendered, show the ‘Get MP3’ text, indicating that both have the custom field set to something (which is not true).
A tag trace shows this for the article with the custom field set:
<txp:if_custom_field name=“mp3-media-url” />
[<txp:if_custom_field name=“mp3-media-url” />: true]
<txp:custom_field name=‘mp3-media-url’ />
…and the same tag trace shows this for the article without the custom field set:
<txp:if_custom_field name=“mp3-media-url” />
[<txp:if_custom_field name=“mp3-media-url” />: false]
<txp:custom_field name=‘mp3-media-url’ />
No diagnostic errors are thrown up, so I’m a bit baffled where I might be going wrong.
Any ideas and advice gratefully received.
Thanks!
Last edited by gaekwad (2012-02-22 19:51:54)
Offline
Re: If a named custom field has something in it, output what's in it
You’ve accidentally put a closing / at the end of your first if_custom_field tag. It should be:
<txp:if_custom_field name="whatever">
Do something
</txp:if_custom_field>
Offline
Re: If a named custom field has something in it, output what's in it
Gah! I knew it was something I’d screwed up – thanks, Phil.
Offline