Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2009-02-25 10:19:09
- Alfie
- Member
- Registered: 2007-11-06
- Posts: 40
multiple templates within a single page using conditional tags?
Hi all,
im probably wording this wrong so i’ll try and explain.
My current TXP site has 4 “page” temnplates: static_page, contact and 2col and portfolio.
Static_page handles 90% of the articles and all pages produced via this page are the same. tag is :<txp:article limit=1 form=“static_article” status=“sticky” />
Contact is the same as Static_page but i have included <txp:output_form form=“contact” /> under the article.
2col uses a plugin to allow me to split up the article into 2 collums and the main article code is <txp:article limit=1 form=“2col” status=“sticky” />
and the last page (portfolio) has this code: <txp:article limit=1 form=“static_article” status=“sticky” />
<txp:article form=“portfolio” pgonly=“0” sort=“title desc” status=“4” time=“any” /> for article output.
The question is: Can I use If statements to put all that in one page template. E.g. <txp:If> “contact section” <txp:output_form form=“contact” /><txp:else><txp:article limit=1 form=“static_article” status=“sticky” />. This would allow me to add all the different parts to forms and only use one template page… or is there an easier way???
I have used this method a few times using smarty templates but not TXP
Any help would be great..
Regards
Alfie
EDIT: working through the TXP solutions book ive found a paragraph entitled “multiple templates within a single page” it reads: “using conditional tags, which are if statements, you can place multiple article tags in a page and define which one is activated depending on where the user is within the site”.
However it only seems to cover excerpts and full blog entrries. Im still working on it as im sure i’ll figure it out but again any input in the mean time would be great.
Alfie
Last edited by Alfie (2009-02-25 10:42:36)
Offline
Re: multiple templates within a single page using conditional tags?
If each of these article types corresponds to a section you could certainly do it: this might not be the most elegant, but should work:
<txp:if_section name="static, contact"> <txp:article limit=1 form=“static_article” status="sticky" /> </txp:if_section> <txp:if_section name="contact"> <txp:output_form form="contact" /> </txp:if_section> <txp:if_section name="2col"> <txp:article limit=1 form="2col" status="sticky" /> </txp:if_section> <txp:if_section name="portfolio"> <txp:article form=“portfolio” pgonly="0" sort="title desc" status="4" time="any" /> </txp:if_section>
Code is topiary
Offline
#3 2009-02-25 14:27:26
- Alfie
- Member
- Registered: 2007-11-06
- Posts: 40
Re: multiple templates within a single page using conditional tags?
Thankyou for the quick response That does look exatly like what i was after,
Cheers
Alfie
Offline
#4 2009-02-25 17:44:55
- Alfie
- Member
- Registered: 2007-11-06
- Posts: 40
Re: multiple templates within a single page using conditional tags?
ok it seemed to work flawlesly, i added a few bits and pieces and all was good, only problem is that now im getting
Tag error: -> Textpattern Notice: Page template staticbkp does not contain a txp:article tag on line 474 when i click on a permalink within the portfolio section.
the form “portfolio” is as follows.
<txp:if_article_list>
<!-- we're in an article list context -->
<div class="article">
<div class="article-image">
<txp:permlink> <txp:hak_article_image limit="1" link="0" /></txp:permlink>
</div>
<div class="article-body">
<txp:excerpt />
<txp:permlink>Read More ..</txp:permlink>
</div>
</div>
<txp:else />
<!-- we're in an individual article (permanent link) context -->
<div class="article">
<div class="article-image1"> <txp:hak_article_image limit="1" link="0"/>
<txp:hak_article_thumb link="1" rel="lightbox-smd" />
</div>
<div class="article-body1">
<txp:body />
</div>
</div>
</txp:if_article_list>
As soon as i take the portfolio line out of the if_section all is ok again..
Any help would be a-mazing!!!
Regards
Alfie
Offline
#5 2009-02-25 18:25:29
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: multiple templates within a single page using conditional tags?
Alfie wrote:
Tag error: -> Textpattern Notice: Page template staticbkp does not contain a txp:article tag on line 474 when i click on a permalink within the portfolio section.
It doesn’t really matter, the notice won’t be displayed if you change Production status to ‘Live’. If you don’t want to see it anyway, you can add <txp:article pgonly="1" limit="1" />
somewhere on that page.
Offline
#6 2009-02-25 20:03:37
- Alfie
- Member
- Registered: 2007-11-06
- Posts: 40
Re: multiple templates within a single page using conditional tags?
Thank for the reply, the only issue is though that the article that is supposed to be there is completelly missing, thus leaving a big blank space.
Ill give adding that line a go.
regards
Alfe
Offline