Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 Yesterday 18:18:08

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,250
Website Mastodon

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

#2 Yesterday 19:02:44

etc
Developer
Registered: 2010-11-11
Posts: 5,652
Website GitHub

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

#3 Yesterday 20:28:09

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,158
Website GitHub

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

#4 Today 00:51:36

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,250
Website Mastodon

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

#5 Today 07:33:34

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,379
Website GitHub

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

Board footer

Powered by FluxBB