How do you access page variables with SMARTY?

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
kendo451

How do you access page variables with SMARTY?

Post by kendo451 »

I would like to use the page alias as the id for a certain DIV like so:

Code: Select all

<div id="{$alias}">
However this doesn't work.

What is the correct syntax to do this?

Thanks,
Ken
viebig

Re: How do you access page variables with SMARTY?

Post by viebig »

Hello again Ken,

One way to do that is creating  a UDT (User Defined Tag). (Extensions -> User Defined Tags)

Name it pagealias, and add put this code:

Code: Select all

global $gCms;
return $gCms->variables['page_name'];
then you can use it anywhere, for example, if you page alias is 'home'

Code: Select all


<div id="{pagealias}"></div>

would return

<div id="home"></div>
Hope that helps you!
kendo451

Re: How do you access page variables with SMARTY?

Post by kendo451 »

Thanks, V!

I also found that there is already a variable for this {$page_alias}.  And this works.

Can someone create a documentation page in the wiki that lists all the page variables that can be accessed from a template using SMARTY?  I would much rather consult a page like that than ask a question in the forum.

Thanks!
Ken
alby

Re: How do you access page variables with SMARTY?

Post by alby »

kendo451 wrote: Can someone create a documentation page in the wiki that lists all the page variables that can be accessed from a template using SMARTY?  I would much rather consult a page like that than ask a question in the forum.
If you add:
{get_template_vars}

you have all local smarty variables (core+modules)

Alby
kendo451

Re: How do you access page variables with SMARTY?

Post by kendo451 »

Ahhh!  Thanks, Alby!  That's a great trick!

So now I will go write that documentation page myself. :-)
Locked

Return to “CMSMS Core”