Category dependant includes

Discuss PivotX 2.0.x themes here, and view themes that are available for download.

Category dependant includes

Postby Stro » Thu Dec 24, 2009 8:33 am

I'm looking for a way to include a category dependant sidebar in my entrypage. I have two separate sidebar files; _sub_sidebar1.html and _sub_sidebar2.html.

If the category in the entrypage is 1, I would like to show _sub_sidebar1.html. If the category in the entrypage is 2, I would like to show _sub_sidebar2.html.

I hoped [[ include file="templatename/_sub_sidebar[[ category ]].html" ]] would work, but I guess it can't be done this way.

Thanks in advance.
Stro
 
Posts: 11
Joined: Thu Dec 24, 2009 8:22 am

Re: Category dependant includes

Postby Bob » Thu Dec 24, 2009 8:05 pm

Hi,

You can't use [[tags]] inside other tags. What you want is to set a variable, and use that.

Code: Select all
[[ assign var=category value=$entry.category.0 ]]
[[ include file="templatename/_sub_sidebar_$category.html" ]]


So if you have a category named 'blabla', it will include _sub_sidebar_blabla.html

Better even, would be to make sure a 'default' is used, for pages that won't fall into either one of those categories.. For instance, the frontpage of the site, and such..

Code: Select all
[[ assign var=category value=$entry.category.0 ]]
[[ if $category!="" ]]
  [[ include file="templatename/_sub_sidebar_$category.html" ]]
[[ else ]]
    [[ include file="templatename/_sub_sidebar_default.html" ]]
[[/if]]
Bob
Lead Developer
 
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm

Re: Category dependant includes

Postby Stro » Tue Dec 29, 2009 5:51 pm

Cheers Bob; exactly what I needed.

Have a great and "Kingly" 2010!
Stro
 
Posts: 11
Joined: Thu Dec 24, 2009 8:22 am


Return to 2.x Themes

Who is online

Users browsing this forum: No registered users and 1 guest

cron