Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Custom fields, txp:if and txp:else
Hello,
I have took and example from Textbook and I have adapted it but it doesn’t work.
<strong>Autor</strong>:
<txp:if_custom_field name=“Autor”>
<txp:custom_field name=“Autor” />
<txp:else /><txp:author link=“0” this_section=“0” /></txp:if_custom_field>
<br/>
Only appears <txp:author link=“0” this_section=“0” /> insted of <txp:custom_field name=“Autor” />
Something wrong ?
I can’t find the error. Textpattern says that everything it’s ok (No errors).
Thanks.
Offline
#2 2008-06-22 20:41:49
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Custom fields, txp:if and txp:else
Aicart wrote:
<strong>Autor</strong>:
<txp:if_custom_field name="Autor">
<txp:custom_field name="Autor" />
<txp:else /><txp:author link="0" this_section="0" /></txp:if_custom_field>
<br/>
This code looks ok to me. There are certain reserved names that should not be used to name custom fields, but Autor is not one of them, so the name can’t be the problem.
Are you absolutely sure that your custom field is not empty? Is the name of the custom field exactly Autor (with capital)?
Otherwise, you can have a look at the tag trace (as described in this FAQ). You can also post the tag trace here, so we can have a look at it.
Offline
Re: Custom fields, txp:if and txp:else
The field is not empty and the name it’s OK.
I have turn off plugins,
This is the code that calls the form.
The other code was in default form.
<txp:article_custom limit="5" pgonly="0" section="articles" sort="Posted desc" status="4" />
This is my tag trace.
<!— txp tag trace:
[SQL (0,007056): select name, data from ai_txptxp_lang as txp_lang where lang=‘ca-es’ AND ( event=‘public’ OR event=‘common’)]
[SQL (0,000716): select name, code, version from ai_txptxp_plugin as txp_plugin where status = 1]
[SQL (0,000828): select * from ai_txptxp_section as txp_section where name = ‘default’ limit 1]
[SQL (0,008896): select host from ai_txptxp_log as txp_log where ip=‘83.61.228.138’ limit 1]
[SQL (0,035862): insert into ai_txptxp_log set `time`=now(),page=’/’,ip=‘83.61.228.138’,host=‘138.Red-83-61-228.staticIP.rima-tde.net’,refer=’‘,status=‘200’,method=‘GET’]
[SQL (0,000782): select user_html from ai_txptxp_page as txp_page where name=‘default’]
[Pàgina: default]
<txp:output_form form=“header” />
[SQL (0,015737): select Form from ai_txptxp_form as txp_form where name=‘header’]
[Formulari: header]
<txp:lang/>
<txp:page_title separator=” | ”/>
<txp:css format=“link” n=“default” />
<txp:feed_link flavor=“atom” format=“link” label=“Atom” />
<txp:feed_link flavor=“rss” format=“link” label=“RSS” />
<txp:article_custom limit=“5” pgonly=“0” section=“articles” sort=“Posted desc” status=“4” />
[SQL (0,029853): select *, unix_timestamp(Posted) as uPosted from ai_txptextpattern as textpattern where 1 and Status = 4 and Posted <= now() and Section = ‘articles’ order by Posted desc limit 0, 5]
[SQL (0,000774): select Form from ai_txptxp_form as txp_form where name=‘default’]
[Formulari: default]
[article 1]
<txp:permlink>
<txp:title/>
</txp:permlink>
<txp:excerpt/>
<txp:if_custom_field name=“Autor”>
[<txp:if_custom_field name=“Autor”>: false]
<txp:author link=“0” this_section=“0” />
[SQL (0,000412): select RealName from ai_txptxp_users where `name` = ‘aicart’ limit 1]
</txp:if_custom_field>
<txp:posted gmt=“1” />
<txp:category1 link=“1” title=“1” section=“articles” this_section=“1” />
[SQL (0,006239): select title from ai_txptxp_category as txp_category where name=‘misc’ and type=‘article’]
<txp:keywords/>
<txp:output_form form=“footer” />
[SQL (0,003466): select Form from ai_txptxp_form as txp_form where name=‘footer’]
[Formulari: footer]
[ ~~~ secondpass ~~~ ]
—>
Any ideas ?
Last edited by Aicart (2008-06-22 20:55:25)
Offline
#4 2008-06-22 21:13:27
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Custom fields, txp:if and txp:else
[<txp:if_custom_field name="Autor">: false]
It definitely says ‘false’… I hate to repeat myself but are you really, absolutely sure that the custom field ‘Autor’ is filled for your article #1?
Does it work when you use another custom field (with another name)?
Offline
Re: Custom fields, txp:if and txp:else
I have changed the field’s name to autor_externo and it works perfectly. Could be the capital letter ?
Maybe a bug?
Thanks.
Offline
#6 2008-06-22 21:50:55
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,306
Re: Custom fields, txp:if and txp:else
Aicart wrote:
Could be the capital letter ?
Definitely not. From the textbook entry on custom_field
Custom names may include letters (uppercase or lowercase), numbers and under_scores, but no spaces or other special characters. There are certain names reserved by Textpattern, which should not be used to name custom fields. They include: thisid, posted, annotate, comments_invite, authorid, title, url_title, category1, category2, section, keywords, article_image, comments_count, body, excerpt, and status.
And Autor isn’t among. Odd! Maybe you’ve had an unnoticed blank after it? We’ll never know :)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#7 2008-06-22 21:52:08
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Custom fields, txp:if and txp:else
That’s strange, TextBook says this:
Custom names may include letters (uppercase or lowercase), numbers and under_scores, but no spaces or other special characters.
I’ll move this topic to Developer Support, so a dev can shed some light on this.
But I’m glad you got it to work :)
Edit: ah, Uli was faster :)
Last edited by els (2008-06-22 21:52:32)
Offline
Re: Custom fields, txp:if and txp:else
Thanks for all :)
Offline