Page 1 of 1
How do you access page variables with SMARTY?
Posted: Mon Sep 15, 2008 4:53 pm
by kendo451
I would like to use the page alias as the id for a certain DIV like so:
However this doesn't work.
What is the correct syntax to do this?
Thanks,
Ken
Re: How do you access page variables with SMARTY?
Posted: Mon Sep 15, 2008 6:20 pm
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!
Re: How do you access page variables with SMARTY?
Posted: Mon Sep 15, 2008 6:46 pm
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
Re: How do you access page variables with SMARTY?
Posted: Tue Sep 16, 2008 8:26 am
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
Re: How do you access page variables with SMARTY?
Posted: Tue Sep 16, 2008 8:42 pm
by kendo451
Ahhh! Thanks, Alby! That's a great trick!
So now I will go write that documentation page myself.
