Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-07-19 16:30:28

kritoke
Member
From: Florida
Registered: 2010-07-19
Posts: 26

If All But One Section

I am currently migrating a site and completely redesigning it in the process from Wordpress to Textpattern. I am finding myself wanting to be able to output something if it is any section but one specific section. I have a good number of sections and having to do like 5 or 6 checks for sections just to get to an else is a pretty inefficient code-wise, I was wondering if there is a more elegant way of doing this. Even being able to do the reverse would be okay, i.e. (here is some pseudocode to better illustrate what I would like to achieve):

if (section != doNotOutputSection)
{
// Output some cool design elements for all the sections but doNotOutputSection
}
else {
// Output stuff for doNotOutputSection
}

or

if (section == doNotOutputSection)
{
// Output stuff for doNotOutputSection
}
else {
// Output some cool design elements for all the sections but doNotOutputSection

}

Any ideas?

Kritoke

Offline

#2 2010-07-19 16:34:12

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: If All But One Section

Hi kritoke:

<txp:if_section section="doNotOutputSection">
// Output stuff for doNotOutputSection
<txp:else />
// Output some cool design elements for all the sections but doNotOutputSection
</txp:if_section>

Hope that helps.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2010-07-20 17:34:54

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: If All But One Section

Generally all the if/else TXP tags should be inhaled :)


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#4 2010-07-20 18:19:42

kritoke
Member
From: Florida
Registered: 2010-07-19
Posts: 26

Re: If All But One Section

The main thing I am trying to do is not output a dividing line if it is on the front page (I am pulling the latest article from each section, making kind of a magazine/newspaper style front page, where they already are being divided by a different style line). I am using an excerpt form to output most of my articles for many sections. I would love to be able to just have it output only if the page is not part of the default section. I could do a separate form for the front page, but I really wanted to have the least amount of code repetition as possible just in case I change something in the future, I do not have to update multiple forms.

Offline

#5 2010-07-20 19:08:49

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

Re: If All But One Section

<txp:if_section name="">
   <!-- do nothing -->
<txp:else />
   <!-- here your line -->
</txp:if_section>

Offline

#6 2010-07-20 19:21:33

kritoke
Member
From: Florida
Registered: 2010-07-19
Posts: 26

Re: If All But One Section

Wow, Els. That is so simple, so elegant. I cannot believe I did not think of doing that. I guess what kept me from thinking about doing that, is that I thought the frontpage was somehow its own section (default). It really did the trick.

Offline

#7 2010-07-20 19:33:58

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

Re: If All But One Section

kritoke wrote:

that I thought the frontpage was somehow its own section (default).

You can use either section="" or section="default" to indicate the front page/default section.
BTW, I only repeated what maniquí said a couple of posts up ;)

Offline

Board footer

Powered by FluxBB