Can I do something like {if $content_id == 1}hello world{/if} inside a template to check, if the current page has a certain id? It would be suitable for many different kinds of stuff.
Regards
Nils
IF conditions with SMARTY in templates
Re: IF conditions with SMARTY in templates
Should be able to. Everything that works in Smarty should work in a template or content.
Re: IF conditions with SMARTY in templates
Yes, I know ... but $content_id (the ID of the current page) is not assigned as a variable, or have I missed something? Here's an example what I would like to do: let's say I have a page called "1.1 FAQ" with $content_id 2 and would like to assign a certain header-image to that website, it would be great to have something like {if $content_id == 2}header_02.gif{/if} ... but that would mean, that $content_id is available as a variable within the template.
Regards,
Nils
Regards,
Nils
Re: IF conditions with SMARTY in templates
Ok, long way around to do this, but it does work.
First, make a user defined plugin/tag thing. Call it loadgcms. Put the following code in it:
Now put this in your template/content:
That will show you the current page id.
Hope that helps.
First, make a user defined plugin/tag thing. Call it loadgcms. Put the following code in it:
Code: Select all
global $gCms;
$smarty->assign_by_ref('gCms', $gCms);
Code: Select all
{loadgcms}
<p>Here is the page id: {$gCms->variables.page}</p>
Hope that helps.
Re: IF conditions with SMARTY in templates
Great! That was, what I was looking for. Found out, that I can use {$gCms->variables.position} as well, which is even better, since I can now do something with the site structure, i.e. assign a certain header according to the group this content is in. Actually I use a style on a div and with your kind help I could do something like
variables.position|truncate:1:""}">
Now I have several styles (as many as groups) and with those styles I can assign different header-images (or other stuff) to the website. Thank you again for your help. But there is still one small question (might turn out as a big one): how do I get the ID of the parent element, that I can see in admin-mode ($parent_id) and use it within the website-template? Lots of questions, I know ...
Regards,
Ansgar
variables.position|truncate:1:""}">
Now I have several styles (as many as groups) and with those styles I can assign different header-images (or other stuff) to the website. Thank you again for your help. But there is still one small question (might turn out as a big one): how do I get the ID of the parent element, that I can see in admin-mode ($parent_id) and use it within the website-template? Lots of questions, I know ...
Regards,
Ansgar
Re: IF conditions with SMARTY in templates
Hi,
I have been using variables.page to get the page id but in Tobago (version 0.11.1) this returns the id of the current template in use, not the page id.
Please tell me what to use to get the page id?
Later,
Bangkok Bob
I have been using variables.page to get the page id but in Tobago (version 0.11.1) this returns the id of the current template in use, not the page id.
Please tell me what to use to get the page id?
Later,
Bangkok Bob