Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-06-12 05:27:50

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,457
Website

Is there a better way ? txp_if conditionals

I have the following in my default page template

<html lang="en"<txp:if_author><txp:else /><txp:if_category><txp:else /> class="front"</txp:if_category></txp:if_author>>

Basically, this says: stick a class on the html element, but only if and when we are really, I mean really, on the front page of the site (example.com/index); if a category or an author page are displayed, do nothing. Other sections and search have their own templates anyway.

The question is: is there an easier, more readable way than this cascading of txp_if … txp:else statements ? I have similar thingies elsewhere in the template, and I’m looking at optimising all this.

Tia.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

#2 2011-06-21 01:07:08

mrtunes
Member
From: Toronto, On
Registered: 2007-03-12
Posts: 575
Website

Re: Is there a better way ? txp_if conditionals

i know what you’re saying, but i really can’t imagine it being more readable than this. it’s essentially a derivative of:

if (condition) {
   statements_1
} else {
   statements_2
}

Offline

#3 2011-06-21 07:04:26

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
Website

Re: Is there a better way ? txp_if conditionals

phiw13 a écrit:

is there an easier, more readable way than this cascading of txp_if … txp:else statements ?

Yes : soo_if_frontpage

Offline

#4 2011-06-21 07:51:02

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,457
Website

Re: Is there a better way ? txp_if conditionals

@Elliott – yeah, it is kinda readable – with 2 or 3 levels…

But basically, what I was hinting at: the need for a txp:if_frontpage tag [*]. Turns out, maybe there is such a thing, in the form of a plugin. Merçi Claire. I’m off to test it out.

[*] I know, more easily said than done, there are various threads scattered around the forums with discussions on the subject of ‘frontpage’ vs ‘default’ template (which is quite a rich animal, the more I dive into it).


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

Board footer

Powered by FluxBB