Conditional elements

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
jonit
New Member
New Member
Posts: 6
Joined: Sat Feb 10, 2007 10:50 pm

Conditional elements

Post by jonit »

Is there a way of making certain parts of a template content conditional depending of what page is currently viewed?

I have looked at Smarty and realize that I can use {if}-statements to control the code, but my problem is that I don't know what to use for the actual base the statement on.

I have tried using the CMS user tag {title} but nil...

I think you get the picture, but just to show you what doesn't work, this is the code outline:

{if (Current_Page) == 'HomePage'}
  showSomething
{else}
  showSomethingElse
{/if}

Hints appreciated... Thanks...
/Jon
User avatar
chead
Forum Members
Forum Members
Posts: 63
Joined: Tue Feb 06, 2007 4:01 am
Location: Dallas, TX

Re: Conditional elements

Post by chead »

Yes, you can have conditional code. You're on the right track. You just need to know what variables contain the information you're wanting.

Put {get_template_vars} into the Smarty template you're working with and it will dump out a list of the currently-assigned template variables and their values when you display the page. If one of the variables is an array, you can also use {$variablename|print_r} to output its contents. (Note: you need to view the actual page to see all the variables; using the "Preview" option in the page editor doesn't assign everything that's on the page.)

$page_alias is probably the one you're looking for, based on your example.
jonit
New Member
New Member
Posts: 6
Joined: Sat Feb 10, 2007 10:50 pm

Re: Conditional elements

Post by jonit »

Thanks Chead, got it working now.

However, I didn't get any output from the {get_template_vars} tag. The page "hung up" and all content after the tag went missing...  ??? But never mind - probably something overlooked on the operator side...

Cheers from sunny Sweden - Now with three gold medals in the Downhill World Champs in Åre (just 100 km from here!  ;D
AngelEyes
Forum Members
Forum Members
Posts: 23
Joined: Tue Nov 20, 2007 3:42 pm

Re: Conditional elements

Post by AngelEyes »

Hi,

This is exactly the type of functionality I am after but I am totally new to Smarty and programming in general.

Would you mind sharing your code so I can get the idea?

I want to display different pictures depending on what page or section your are in, is this possible?

Also does smarty code work in the main template, if so do you have to put in some code before the tags to get it to work?

Sorry for all the questions  ;D

Adam

EDIT: I managed to find what I needed here: http://forum.cmsmadesimple.org/index.ph ... 689.0.html
Last edited by AngelEyes on Wed Jul 16, 2008 7:44 am, edited 1 time in total.
Post Reply

Return to “Layout and Design (CSS & HTML)”