Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2017-08-13 04:52:18
- raminrahimi
- Member
- From: India
- Registered: 2013-03-19
- Posts: 278
how to make two condation for if statement (if or)
how to make two condation for if statement : IF
& OR
example:
<txp:if_article_category name="news">
<txp:or />
<txp:if_category name="news">
... here all news related ...
</txp:if_category>
</txp:if_article_category>
Offline
Re: how to make two condation for if statement (if or)
<txp:if_article_list>
<txp:if_category name="news" limit="10">
<article>
<h2><txp:permlink><txp:title /></txp:permlink></h2>
<txp:excerpt />
</article>
<txp:else />
<txp:hide> this is still an article list but not in the news category - other tags</txp:hide>
</txp:if_category>
<txp:else /> <txp:hide>you are now on individual article</txp:hide>
<txp:if_article_category name="news">
<h1><txp:title /></h1>
<txp:body />
<txp:else /><txp:hide>you are on an individual article which is not in the news category</txp:hide>
</txp:if_article_category name="news">
</txp:if_article_list>
the above is untested but you may make your life easier if you use sections
<txp:if_article_list>
<txp:hide>you can have a specific template for the news section</txp:hide>
<txp:else />
<txp:hide>you are on an individual article page</txp:hide>
</txp:article_list>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#3 2017-08-13 05:44:02
- raminrahimi
- Member
- From: India
- Registered: 2013-03-19
- Posts: 278
Re: how to make two condation for if statement (if or)
i’ve lots of codes on the inner of that, but i don’t want to repeat them
is it possible to don’t repeat the codes ?
<txp:if_article_category name="news">
<txp:or />
<txp:if_category name="news">
... here i've lots of codes around 50 lines, and don't want to repeat them ...
</txp:if_category>
</txp:if_article_category>
Offline
Re: how to make two condation for if statement (if or)
raminrahimi wrote #306600:
i’ve lots of codes on the inner of that, but i don’t want to repeat them
is it possible to don’t repeat the codes ?
...
there is no <txp:or />
tag. In order not to have to repeat code you could use a form
<txp:if_article_category name="news">
<txp:hide>you are in an individual article which is in the news category</txp:hide>
<txp:else />
<txp:if_category name="news">
<txp:hide>you are in the news article list category</txp:hide>
<txp:output_form form="newslist" />
</txp:if_category>
</txp:if_article_category>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: how to make two condation for if statement (if or)
If you’re testing OR cases for similar/the same tag, there’s smd_if and smd_multi_choice but in your case for two different cases, I’d probably do it this way without plugins:
<!-- set a variable default state -->
<txp:variable name="show_news_widget">no</txp:variable>
<!-- test condition one and change state if met -->
<txp:if_article_category name="news">
<txp:variable name="show_news_widget">yes</txp:variable>
</txp:if_article_category>
<!-- test condition two and change state if met -->
<txp:if_category name="news">
<txp:variable name="show_news_widget">yes</txp:variable>
</txp:if_category>
<!-- and then where you want your output -->
<txp:if_variable name="show_news_widget" value="yes">
<txp:output_form name="news_widget" />
</txp:if_variable>
Interleave the conditions differently to achieve AND states. If you have a large site with modular components, you might want to put the if_variable statement directly in your output_form (although it may cost you extra db queries).
EDIT: In your particular case, as if_category and if_article_category cannot occur together (mutually exclusive contexts), you could also simply use the output_form directly in the if_category / if_article_category statements and do without the variable. Only one will ever apply depending on whether you’re on an article list or individual article page.
TXP Builders – finely-crafted code, design and txp
Offline