Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
is there a Txp if/else equivalent
Curious If Textpattern tags allow for if/else based on a url title is equal to, do this, else, not.
{if article_id_12 == ""}
<li class="active"><a href="https://textism.ca/brands/logo_ford/"> </a></li>
{/if}
{if article_id_12 != ""}
<li><a href="https://textism.ca/brands/logo_ford/"> </a></li>
{/if}
it would be cool if there was.
…. texted postive
Offline
Re: is there a Txp if/else equivalent
This, maybe?
<txp:if_custom_field name="url_title" value="title_to_match">
yep
<txp:else />
nope
</txp:if_custom_field>
Offline
Re: is there a Txp if/else equivalent
And as an extra, if it’s just to set the class="active" on the currently shown article, you can do:
<li<txp:if_article_id> class="active"</txp:if_article_id>>
<txp:permlink><txp:title /></txp:permlink>
</li>
TXP Builders – finely-crafted code, design and txp
Online
Re: is there a Txp if/else equivalent
So to follow up on my post, what is helpfully suggested, is to replace that code in my example with this:
<li<txp:if_article_id id="33"> class="nav_active"</txp:if_article_id>>
<txp:permlink><txp:title /></txp:permlink>
</li>
<li<txp:if_article_id id="33"> class=nav_plain""</txp:if_article_id>>
<txp:permlink><txp:title /></txp:permlink>
</li>
<li<txp:if_article_id id="41"> class="nav_active"</txp:if_article_id>>
<txp:permlink><txp:title /></txp:permlink>
</li>
<li<txp:if_article_id id="41"> class=nav_plain""</txp:if_article_id>>
<txp:permlink><txp:title /></txp:permlink>
</li>
etc…
UPDATE:
that code outputs the same title 4 times. Not what I expected.
how to output the two titles and only have an active class if the current title is active? thanks!
Last edited by bici (Today 01:13:34)
…. texted postive
Offline
Re: is there a Txp if/else equivalent
bici wrote #342242:
replace that code in my example with [snip]
No. Jools’ suggestion should work as-is. It checks if the current article id matches the individual article being displayed, and adds the class if so.
This is all based on the assumption that you’re displaying your list of 6 portfolio articles at the bottom of an individual article page. Without seeing relevant snippets of your code and the context in which it’s applied, it’s hard to offer advice.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Pages: 1