Page 1 of 1

IF conditions with SMARTY in templates

Posted: Wed May 11, 2005 5:09 pm
by nils73
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

Re: IF conditions with SMARTY in templates

Posted: Wed May 11, 2005 5:19 pm
by Ted
Should be able to.  Everything that works in Smarty should work in a template or content.

Re: IF conditions with SMARTY in templates

Posted: Thu May 12, 2005 10:23 pm
by nils73
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

Re: IF conditions with SMARTY in templates

Posted: Thu May 12, 2005 11:23 pm
by Ted
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:

Code: Select all

global $gCms;
$smarty->assign_by_ref('gCms', $gCms);
Now put this in your template/content:

Code: Select all

{loadgcms}
<p>Here is the page id: {$gCms->variables.page}</p>
That will show you the current page id.

Hope that helps.

Re: IF conditions with SMARTY in templates

Posted: Fri May 13, 2005 8:54 am
by nils73
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

Re: IF conditions with SMARTY in templates

Posted: Tue Dec 20, 2005 9:43 pm
by Bangkok Bob
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