IF conditions with SMARTY in templates

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

IF conditions with SMARTY in templates

Post 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
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: IF conditions with SMARTY in templates

Post by Ted »

Should be able to.  Everything that works in Smarty should work in a template or content.
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: IF conditions with SMARTY in templates

Post 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
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: IF conditions with SMARTY in templates

Post 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.
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: IF conditions with SMARTY in templates

Post 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
Bangkok Bob

Re: IF conditions with SMARTY in templates

Post 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
Post Reply

Return to “Tips and Tricks”