Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-01-19 15:38:18

Lucanos
Member
From: Sydney, Australia
Registered: 2006-01-17
Posts: 23
Website

Nested "If..Else" tags gives "unknown_tag" error

Hey Guys,

I tried searching the forum, but as the keywords here are so genetic it was like finding a straw in a needle-stack…

I am having trouble using nested <txp:if_section…>FOO<txp:else />BAR</txp:if_section> tags. (If there were <txp:elseif_section…> or <txp:switch…><txp:option value=“x”>FOO</txp:option> tags it would be nice, but I didn’t see them in the documentation).

Here is my code:

<txp:if_section name=“ecollection” > <img src=”/images/4.jpg” alt=“The Eclectic Collection – Thursdays 7PM to 9PM” style=“height:80px;width:550px” />
<txp:else /><txp:if_section name=“backseatDriver” > <img src=”/images/9.jpg” alt=“Backseat Driver – Thursdays 5PM to 7PM” style=“height:80px;width:550px” />
<txp:else /> <img src=”/images/10.jpg” alt=“Triple H – 100.1 FM” style=“height:80px;width:550px” />
</txp:if_section>
</txp:if_section>

I’m trying to have a list of possible options, with the generic result being returned in the case of no match.
Testing of this one showed that the first “if_section” test worked, but the nested “if_section” statement seems to be discarded when processed. So true for the first test will return the first section of code, and false will return the last section of code.

Any ideas, suggestions, RTFM Directives (with detailed references?) would be appreciated.

Offline

#2 2006-01-19 16:49:28

KurtRaschke
Plugin Author
Registered: 2004-05-16
Posts: 275

Re: Nested "If..Else" tags gives "unknown_tag" error

FAQ: http://textpattern.com/faq/39/problems-with-nested-txpif_-tags

-Kurt


kurt@kurtraschke.com

Offline

#3 2006-01-19 16:51:11

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Nested "If..Else" tags gives "unknown_tag" error

Here’s your post again with < code> < /code> tags ;)

I am having trouble using nested <txp:if_section...>FOO<txp:else />BAR</txp:if_section> tags. (If there were <txp:elseif_section...> or <txp:switch...><txp:option value="x">FOO</txp:option> tags it would be nice, but I didn’t see them in the documentation).

Here is my code:
<code>
<txp:if_section name=“ecollection” >
<img src=”/images/4.jpg” alt=“The Eclectic Collection – Thursdays 7PM to 9PM” style=“height:80px;width:550px” />
<txp:else /><txp:if_section name=“backseatDriver” >
<img src=”/images/9.jpg” alt=“Backseat Driver – Thursdays 5PM to 7PM” style=“height:80px;width:550px” />
<txp:else />
<img src=”/images/10.jpg” alt=“Triple H – 100.1 FM” style=“height:80px;width:550px” />
</txp:if_section>
</txp:if_section>
</code>
I’m trying to have a list of possible options, with the generic result being returned in the case of no match.
Testing of this one showed that the first “if_section” test worked, but the nested “if_section” statement seems to be discarded when processed. So true for the first test will return the first section of code, and false will return the last section of code.

You can only nest conditional tags that are not the same. So for instance
<code>
<txp:if_section>
<txp:if_category>
blah
</txp:if_category>
</txp:if_section>
</code>
is possible. But it’s not possible to nest more than one <txp:if_section> tag.

I think this would work:
<code>
<txp:if_section name=“ecollection” >
<img src=”/images/4.jpg” alt=“The Eclectic Collection – Thursdays 7PM to 9PM” style=“height:80px;width:550px” />
</txp:if_section>
<txp:if_section name=“backseatDriver” >
<img src=”/images/9.jpg” alt=“Backseat Driver – Thursdays 5PM to 7PM” style=“height:80px;width:550px” />
</txp:if_section>
<txp:if_section name=“ecollection,backseatDriver”>
<txp:else />
<img src=”/images/10.jpg” alt=“Triple H – 100.1 FM” style=“height:80px;width:550px” />
</txp:if_section>
</code>

Offline

#4 2006-01-19 17:01:18

Lucanos
Member
From: Sydney, Australia
Registered: 2006-01-17
Posts: 23
Website

Re: Nested "If..Else" tags gives "unknown_tag" error

Gentlemen,

Thank you kindly for your assistance, and the provided solution (which I will be sure to use).
Apologies for not finding it in the FAQ myself, I will be sure to look three times next time rather than the two times I looked on this occasion.

Once again, thank you.

Luke

Offline

Board footer

Powered by FluxBB