Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-10-26 19:41:48

jordanwollman
Member
From: Dallas, TX
Registered: 2005-08-25
Posts: 19
Website

Use one template for multiple sections

I ran across a post a while back that explained how to do this, but I couldn’t understand it. I’ve almost completely finished my site, but I’ve created a different template for each section, and to do this to get the right content to show up: <code><txp:article_custom form=“article_body_only” category=“contact” section=“Contact” /></code>

Can someone please explain how to do what I’m asking?

Thanks in advance.


Jordan Wollman [url=http://www.fringeimage.com/]// Fringe Image[/url][/color]

Offline

#2 2005-10-26 19:55:13

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Use one template for multiple sections

In the content area of your template you need to split your code into blocks to tell TXP what to display when it is in each section. You can do this using the <code><txp:if_section name=SectionName”></code> tag provided you are on a newer install of TXP. You are advised to move up to 4.0.1 if you haven’t already. The code blocks would each follow this simple format:-

<code>
<txp:if_section name=“hobnobs”>
<txp:article limit=“5” form=“hobnobs” />
</txp:if_section></code>
<br />

You need a block for each of your sections. You can put what you want between the tags, I’m only showing an article output.


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#3 2005-10-26 20:05:27

jordanwollman
Member
From: Dallas, TX
Registered: 2005-08-25
Posts: 19
Website

Re: Use one template for multiple sections

Ah… So, I have to add an “if_section” for each section? I guess that makes sense.

Awesome! Works great!

Thanks for the info.

Last edited by jordanwollman (2005-10-26 20:10:44)


Jordan Wollman [url=http://www.fringeimage.com/]// Fringe Image[/url][/color]

Offline

#4 2005-10-26 20:22:27

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Use one template for multiple sections

Well if you had a couple of sections that used the same layout and were only different in that they showed different articles from different sections, you could use <code><txp:if_section name=“about,contact,single”></code>, that is, a comma-separated list but that won’t be available until 4.0.2 I’m afraid. Worth waiting for though. :)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#5 2005-10-26 21:09:29

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Use one template for multiple sections

What are you using categories for?

The usual way would be to simply use <txp:article form="article_body_only" />.


Alex

Offline

#6 2005-10-26 21:27:51

jordanwollman
Member
From: Dallas, TX
Registered: 2005-08-25
Posts: 19
Website

Re: Use one template for multiple sections

I was using categories because when I started making this site, I didn’t know the difference between them and sections. So, by default, they both got the same name. :D


Jordan Wollman [url=http://www.fringeimage.com/]// Fringe Image[/url][/color]

Offline

#7 2005-10-26 21:39:57

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Use one template for multiple sections

A simple <txp:article from="article_body_only" /> tag should do the job then. No need for conditionals, unless one section requires a slightly different display – in that case, use txp:if_section, as tbs suggests.


Alex

Offline

#8 2005-10-26 21:50:25

jordanwollman
Member
From: Dallas, TX
Registered: 2005-08-25
Posts: 19
Website

Re: Use one template for multiple sections

That seems to work… However, what’s the difference between <code><txp:article /></code> and <code><txp:article_custom /></code> ?

Also, I want to use <code><txp:article /></code> for the “Blog” section, but use <code><txp:article form=“article_body_only” /></code> for all other pages.

Is there a way to do an “Else” statement?

Last edited by jordanwollman (2005-10-26 22:02:56)


Jordan Wollman [url=http://www.fringeimage.com/]// Fringe Image[/url][/color]

Offline

#9 2005-10-26 23:59:59

oldi
Member
Registered: 2005-10-14
Posts: 87

Re: Use one template for multiple sections

There is an explanation in <a href=“http://textpattern.com/faq/85/what-does-article_custom-do” title=“FAQ”>FAQ</a> about <code><txp:article /> and <txp:article_custom/></code>. But i am new to all this so cant give more real life example of that.

I had the same question about templates and multiple section. Reading this helped me to delete some of the pages, since i had one page per section. But what about static pages. Can’t they be set up with if_section why according to <a href=“http://textpattern.com/faq/31/how-do-i-manage-static-pages” title=“FAQ”>FAQ</a> they need a seperate page?

Offline

#10 2005-10-27 06:34:57

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

Re: Use one template for multiple sections

Also, I want to use <code><txp:article /></code> for the “Blog” section, but use <code><txp:article form=“article_body_only” /></code> for all other pages.

Is there a way to do an “Else” statement?

<code><txp:if_section name=“blog”>
<txp:article />
<txp: else />
<txp:article form=“article_body_only” />
</txp:if_section>
</code>

Offline

#11 2005-10-27 06:45:31

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

Re: Use one template for multiple sections

But what about static pages. Can’t they be set up with if_section why according to <a href=“http://textpattern.com/faq/31/how-do-i-manage-static-pages” title=“FAQ”>FAQ</a> they need a seperate page?

They don’t need a separate page template, though it can be preferable if you have different styles for those sections. But even then you could solve that by doing something like this:
<code>
<txp:if_section name=“section1”>
<div id=“section1”>
</txp:if_section>
<txp:if_section name=“section2”>
<div id=“section2”>
</txp:if_section>
<txp:if_section section=“section1”>
content for section1
</txp:if_section>
<txp:if_section section=“section2”>
content for section2
</txp:if_section>
</div>
</code>
I’ve got sites with some 8-10 sections, using only one page template.

Offline

#12 2005-10-27 12:40:57

jordanwollman
Member
From: Dallas, TX
Registered: 2005-08-25
Posts: 19
Website

Re: Use one template for multiple sections

Thanks for the “Else” statement. I had it SO CLOSE. I didn’t have the trailing /.


Jordan Wollman [url=http://www.fringeimage.com/]// Fringe Image[/url][/color]

Offline

Board footer

Powered by FluxBB