Page 1 of 1

Custom variables

Posted: Tue Feb 20, 2007 11:53 am
by mattots
Hi,

I'm new to the forum. I've just started using CMSMS so no doubt I'll have a few questions over the coming weeks and months!

What I would like to be able to do is assign custom variables to specific pages. For example, I want to highlight a particular menu item when you're on any of the sub-pages within that section of the site. Of course, I can do this by putting some php in my template that checks the alias of all the pages in the section and sets a css class, eg.

Code: Select all

if ($alias == 'about-us' || $alias == 'contact-us' || $alias == 'recruitment' etc.etc.etc.) {
echo 'class="highlight"';
}
But it would be much neater to just say:

Code: Select all

if ($custom_variable == 'bob') {
echo 'class="highlight"';
}
Is there any way of doing this, or something similar? Potentially there could be a need to assign several custom variables to a page - other uses would be to pull in page-specific stylesheets or scripts, etc.

Sorry if I'm being thick and there's already a way to do this!

Matt

Re: Custom variables

Posted: Sun Jul 27, 2008 7:00 pm
by sn3p
If you want to display user dependant content check out the FrontEndUsers and CustomContent modules.
I'm not sure if this is what you want, but hope it helps.

Re: Custom variables

Posted: Mon Jul 28, 2008 12:16 am
by kermit
for the first thing, highlighting current or active (parent) pages; look at the menu templates that are installed with the sample content.. an extra class is already added to menu items that are the currently active page or an active parent page (when one of its child pages is active), which you can use to style those items differently via css.

for the second thing, page-specific content.. you can use $page_alias within a template to test for current page alias: {if $page_alias eq 'my-special-page'}{/if}

for page-specific css or scripts; simply include those in that page's metadata; if used on more than one page, then put the reused code in a global content block and refer to that instead in the metadata. remember, if code has curly-braces (like scripts and css), wrap the code around {literal} .... {/literal} tags so smarty (the template engine) won't try to interpret it.