Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-08-18 19:18:16

rathersplendid
Plugin Author
From: London
Registered: 2008-05-02
Posts: 163
Website

Is there a way have an if statement for two tags? if_1 and if_2 ...

What I would ideally like is to have an <txp:if_individual_article> and an <txp:if_section> tag together so that I do not have to do some strange if/else tag.

An example: <txp:if_individual_article and if_section="news,about" /> Do you see what I mean?

I have had a brief look at smd_if but I’m not sure if it works with TXP tags but instead variables. Please point me in the right direction.

Many thanks


Admin Themes Prometheus | Stung | <txp:coder/
My Portfolio | ɹǝpuɐz.com | @MrMartineau
<txp:coder /> – Convert your designs into Textpattern-based websites
jQuery Style | @jquerystyle

Offline

#2 2009-08-18 19:21:39

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

Re: Is there a way have an if statement for two tags? if_1 and if_2 ...

<txp:if_section name="news,about">
	<txp:if_individual_article>
		your content
	</txp:if_individual_article>
</txp:if_section>

Offline

#3 2009-08-18 22:53:47

rathersplendid
Plugin Author
From: London
Registered: 2008-05-02
Posts: 163
Website

Re: Is there a way have an if statement for two tags? if_1 and if_2 ...

Thanks Els, but unless I’m not understanding the TXP tags correctly, I think that the code you supplied means to show any individual article within the news or about sections. Is that what you mean? or does your code mean, any individual article and the sections, news and about, show the content? Please tell me it is the latter.

I want the contained code to be present on an individual article as well as an article list. Some sections need to have the code, some don’t, hence the if_section while all individual articles need to have the code.

Thanks for your suggestion and sorry for any confusion.


Admin Themes Prometheus | Stung | <txp:coder/
My Portfolio | ɹǝpuɐz.com | @MrMartineau
<txp:coder /> – Convert your designs into Textpattern-based websites
jQuery Style | @jquerystyle

Offline

#4 2009-08-19 07:18:58

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,732
Website

Re: Is there a way have an if statement for two tags? if_1 and if_2 ...

if_individual_article tests the viewing context, so Els’ code will show when an individual article is being viewed that is in the sections “news” or “about”. Is that what you wanted?

That won’t help for article lists, though, as an article list is not “individual article context”. Here you will need if_article_section in your txp:article form that you use to show the items in your article list.


TXP Builders – finely-crafted code, design and txp

Offline

#5 2009-08-19 16:25:03

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

Re: Is there a way have an if statement for two tags? if_1 and if_2 ...

rathersplendid wrote:

Please tell me it is the latter.

No, sorry, I thought you meant the former…

I want the contained code to be present on an individual article as well as an article list.

In that case you’ll just have to use two sets of tags, one with if_section and one with if_individual_article. To avoid your content being duplicated when in on an individual article page within those two sections, you can do this (you may use if_article_section instead of if_section, like Jakob said, but since an individual article is always displayed on it’s own section page, I think it doesn’t matter):

<txp:if_individual_article>
	<txp:if_section name="news,about">
	<txp:else />
		your content
	</txp:if_section>
</txp:if_individual_article>

<txp:if_section name="news,about">
	<txp:if_article_list>
		your content
	</txp:if_article_list>
</txp:if_section>

If you find that too much code, you’ll have to give smd_if a try to see if the plugin can do it with just one statement. If you can’t figure out how to use it, just ask in the plugin thread :)

Last edited by els (2009-08-19 16:25:33)

Offline

Board footer

Powered by FluxBB