Page 1 of 1
Using template variables to change page [solved]
Posted: Fri Aug 22, 2008 10:43 am
by howey
Hi
I am new to CMS MS and php smarty etc.
I am working on a site and have used cataloger to display projects, and I have been able to alter the cataloger item template to display only those fields that have content
where client is one of the fields.
It would be useful to be able to change the template on a basic page dependent on the content. ie I have two content blocks, if the second content block doesn't have any "content" I would like to be able to change the display so that the containing div is not displayed. I was assuming that if I could find the template variables that I would be able to implement something similar to the above. However, I can't find the required variables. I have used the TAG
but the content block variables are not shown.
Am I on the right track? is so how can I find the variables. I did see a post about a UDT, but as I am not a programmer I don't know what this is, or what I need to do with the examples given.
Re: Using template variables to change page
Posted: Tue Aug 26, 2008 10:14 am
by howey
Hi
I searched using google and did find some information – and found the bit about assign in the TAG information. However, I am still having problems using the assign parameter. I may have missed something realy simple but this is the code I have been using.
Code: Select all
<div class="left2Column width7x9_756">
{if !empty($imagevar) }
<div class="left2Column width3x9_324">
<div class="contentImg">
<h1> </h1>
{content block='image' assign=imagevar }
</div>
</div>
<div class="right2Column width4x9_432">
<div class="contentOverview">
<h1>{title}</h1>
{content}
</div>
</div>
{else}
<div class="right2Column width6x9_648">
<div class="contentOverview">
<h1>{title}</h1>
{content}
</div>
</div>
{/if}
</div>
As you can probably see if the content block 'image" has no content entered then I wanted to to change the layout accordingly, with a slightly bigger text block.
I achieved this in a cataloger template as below:
Code: Select all
{if $2client!=''}
<h1>Project Details</h1>
<p>{$2client}</p>
{if $3maincontractor!=''}
<p>{$3maincontractor}</p>
{/if}
{if $4architects!=''}
<p>{$4architects}</p>
{/if}
{if $5structuralengineers!=''}
<p>{$5structuralengineers}</p>
{/if}
{if $6quantitysurveyor!=''}
<p>{$6quantitysurveyor}</p>
{/if}
{if $7tonnesofsteelused!=''}
<p>{$7tonnesofsteelused}</p>
{/if}
{if $8contractduration!=''}
<p>{$8contractduration}</p>
{/if}
{/if}
the first code always seems to return as empty even when there is an image inserted. I have tried alternatives ie
Code: Select all
{if empty($imagevar) } and {if $imagevar!=''}
Any suggestions? I spent the weekend trying different approaches without success.
Re: Using template variables to change page - using content assign?
Posted: Tue Aug 26, 2008 3:19 pm
by howey
Tried some extra solutions - no luck. But do I have to make the assign a variable?
Re: Using template variables to change page
Posted: Tue Aug 26, 2008 3:22 pm
by cyberman
You can check with {get_template_vars} which variables are available ...
Re: Using template variables to change page
Posted: Tue Aug 26, 2008 3:57 pm
by howey
Used the
before I put in the
statement.
I got this list – the imagevar relates to the assign value in the content tag.
Footer InformationSCRIPT_NAME = /index.php
app_name = CMS
sitename = Conder Structures
lang = en_US
encoding = UTF-8
gCms = Object
content_id = 66
page = market-sectors
page_id = market-sectors
page_name = market-sectors
page_alias = market-sectors
position = 00003
friendly_position = 3
menuparams = Array
count = 7
nodelist = Array
node = Object
imagevar =
prevpage =
lastpage = >>
pagenumber = 1
pagecount = 1
oftext = of
pagetext = Page
itemcount = 1
items = Array
category_label = Category:
author_label = Posted by:
param_number = 2
param_module = News
entry = Object
However, when I put in the
statement the imagevar disapeared.
Template code below:
Code: Select all
{if $imagevar!='' }
<div class="left2Column width3x9_324">
<div class="contentImg">
<h1> </h1>
{content block='image' assign='imagevar'}
</div>
</div>
<div class="right2Column width4x9_432">
<div class="contentOverview">
<h1>{title}</h1>
{content}
</div>
</div>
{else}
<div class="right2Column width6x9_648">
<div class="contentOverview">
<h1>{title}</h1>
{content}
</div>
</div>
{/if}
I had added some text into the content through the wysiwyg editor but it seems to write the "else" option!
I did some searching and I think other people are having trouble – but I haven't found a solution yet.
Re: Using template variables to change page
Posted: Tue Aug 26, 2008 4:18 pm
by cyberman
howey wrote:
{if $imagevar!='' }
{content block='image' assign='imagevar'}
{title}
{content}
{else}
{title}
{content}
{/if}
Maybe you should look at the source once again

. You cannot access a variable before it's defined.
This should work
Code: Select all
{content block='image' assign='imagevar'}
{if $imagevar!='' }
<div class="left2Column width3x9_324">
<div class="contentImg">
<h1> </h1>
<img src="uploads/images/$imagevar.jpg" ... />
</div>
</div>
<div class="right2Column width4x9_432">
<div class="contentOverview">
<h1>{title}</h1>
{content}
</div>
</div>
{else}
<div class="right2Column width6x9_648">
<div class="contentOverview">
<h1>{title}</h1>
{content}
</div>
</div>
{/if}
Re: Using template variables to change page
Posted: Wed Aug 27, 2008 11:26 am
by howey
Thanks for the reply - I'm still struggling though.
I used the code you posted and the template behaves as if there is content there when an image has been inserted into the content block image , in that it writes the first "statement" rather than the else. But it doesn't display the image only a the img tag without anything showing! I played around with it including variations showing the variable.
Code: Select all
<img src="uploads/images/{$imagevar.jpg}" />
Code: Select all
<div class="left2Column width7x9_756">
<div class="left2Column width3x9_324">
<div class="contentImg">
<h1> </h1>
<img src="uploads/images/$imagevar.jpg" ... />
</div>
</div>
<div class="right2Column width4x9_432">
<div class="contentOverview">
<h1>test page</h1>
<p>Test Text</p>
</div>
</div>
</div>
<div class="right2Column width2x9_216">
<div class="contentRightColumn">
<h1> </h1>
<p>Test Right</p>
</div>
</div>
The code from the sub template in cataloger works – only displaying those items that have had content added through the wysiwig
Code: Select all
<div class="contentRightColumn">
{if $2client!=''}
<h1>Project Details</h1>
<p>{$2client}</p>
{if $3maincontractor!=''}
<p>{$3maincontractor}</p>
{/if}
{if $4architects!=''}
<p>{$4architects}</p>
{/if}
{if $5structuralengineers!=''}
<p>{$5structuralengineers}</p>
{/if}
{if $6quantitysurveyor!=''}
<p>{$6quantitysurveyor}</p>
{/if}
{if $7tonnesofsteelused!=''}
<p>{$7tonnesofsteelused}</p>
{/if}
{if $8contractduration!=''}
<p>{$8contractduration}</p>
{/if}
{/if}
</div>
Re: Using template variables to change page
Posted: Wed Aug 27, 2008 11:37 am
by cyberman
Yes, you where right (my fingers were faster than my brain

) - Smarty Variables must be inside {} so you have to use {$imagevar} like here
You have to check if the path to the image is correct. And in the additional content block "imagevar" you have only to insert the name of the picture (without extension like .jpg, .gif ...)
Re: Using template variables to change page
Posted: Wed Aug 27, 2008 11:42 am
by howey
Hi
Just noticed something strange!
I decided for the time being to have two separate templates and let the editor choose the template dependent on content.
At first I left the
in the content tag along with the
. The image still didn't display. The image displayed as soon as I removed the
So I changed the template code to:
Code: Select all
{content block='image' assign='imagevar'}
{if $imagevar!='' }
<div class="left2Column width3x9_324">
<div class="contentImg">
<h1> </h1>
{content block='image'} using the content tag without the "assign="
</div>
</div>
<div class="right2Column width4x9_432">
<div class="contentOverview">
<h1>{title}</h1>
{content}
</div>
</div>
{else}
<div class="right2Column width6x9_648">
<div class="contentOverview">
<h1>{title}</h1>
{content}
</div>
</div>
{/if}
and it seems to work. I presume that if the assign= is in the content tag it only creates a variable and doesn't generate the "content" given in the wysiwig.
I would be interested in any comments – but I think it is solved!
Re: Using template variables to change page
Posted: Wed Aug 27, 2008 11:52 am
by cyberman
howey wrote:
I presume that if the assign= is in the content tag it only creates a variable and doesn't generate the "content" given in the wysiwig.
Once again right

...
Re: Using template variables to change page
Posted: Wed Aug 27, 2008 12:59 pm
by howey
Thanks for all the help Cyberman.
It is so nice to have help pointing me in the right direction.
Cheers
Re: Using template variables to change page [solved]
Posted: Wed Aug 27, 2008 3:18 pm
by cyberman
You're welcome ...