Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2007-12-11 00:07:53
- nasv
- Member
- Registered: 2005-11-14
- Posts: 22
can TXP support nested IF-ELSE?
I’m on 4.0.5:
I’m trying to nest if-else statements based on txp:if_custom_field… the first check is to see if there is a value assigned to a specific custom field, and the second check determines behavior based on the value of that custom-field.
When using this code, I get this error:
Tag error: <txp:else/> -> Textpattern Warning: tag does not exist on line 973
Any ideas? (or some stupid mistake)
-Nico
<txp:if_custom_field name="tumblefeedid" >
<!-- FEED-ID EXISTS -->
<txp:if_custom_field name="tumblefeedid" val="A" >
<!-- THIS IS FEED_A -->
<p>Feed_A specific invite: </p>
<h3><a href="<txp:custom_field name="tumblesourcelink" />" ><txp:title /></a></h3>
<txp:body />
<txp:else />
<!-- this is NOT Feed_A -->
<p>Non-Feed_A invite</p>
<h3><a href="<txp:custom_field name="tumblesourcelink" />" ><txp:title /></a></h3>
<txp:body />
</txp:if_custom_field>
<txp:else />
<!-- NO FEED-ID EXISTS!!! -->
<p>Invite with no feed-id</p>
<h3><a href="<txp:custom_field name="tumblesourcelink" />" ><txp:title /></a></h3>
<txp:body />
</txp:if_custom_field>
Offline
Re: can TXP support nested IF-ELSE?
You cannot nest the same tag within itself.
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: can TXP support nested IF-ELSE?
You can however move the nested tag into another form and call that form through <txp:output_form />
and everything works. Your code becomes:
<txp:if_custom_field name="tumblefeedid" >
<!-- FEED-ID EXISTS -->
<txp:output_form form="feed-check" />
<txp:else />
<!-- NO FEED-ID EXISTS!!! -->
<p>Invite with no feed-id</p>
<h3><a href="<txp:custom_field name="tumblesourcelink" />" ><txp:title /></a></h3>
<txp:body />
</txp:if_custom_field>
then in the feed-check form place:
<txp:if_custom_field name="tumblefeedid" val="A" >
<!-- THIS IS FEED_A -->
<p>Feed_A specific invite: </p>
<h3><a href="<txp:custom_field name="tumblesourcelink" />" ><txp:title /></a></h3>
<txp:body />
<txp:else />
<!-- this is NOT Feed_A -->
<p>Non-Feed_A invite</p>
<h3><a href="<txp:custom_field name="tumblesourcelink" />" ><txp:title /></a></h3>
<txp:body />
</txp:if_custom_field>
Shoving is the answer – pusher robot
Offline
#4 2007-12-11 01:49:43
- nasv
- Member
- Registered: 2005-11-14
- Posts: 22
Re: can TXP support nested IF-ELSE?
wow hakjoon, that’s a good tip… quite a hack IMHO, but I’ll definitely try it first thing tomorrow :-) I guess it should be enough for the TXP parser/interpreter to get past the nested if’s “headache”.
Thanks again, I’ll report back if it doesn’t work.
-Nico
Offline
Re: can TXP support nested IF-ELSE?
nasv – it’s not the nested “if” or indeed the nested“else” that causes the problem. TXP can cope with those provided they belong to different tags and are in the correct order. It’s the same tag within itself that’s the headache though I’m pretty sure that Hakjoon’s method will cure it. I just mention it so that you don’t have problems in the future with thinking TXP can’t do something when it can. :)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Pages: 1