|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
powerobject Smarty Rookie
Joined: 14 Jan 2006 Posts: 18
|
Posted: Mon Apr 24, 2006 9:39 am Post subject: Equivalent of isset() |
|
|
Since I don't want to use PHP inside templates, is there an equivalent for isset() to see if the variable is passed or set? Eg:
{include file='file.tpl' var='value'}
In some cases, I may have to just do:
{include file='file.tpl'}
Inside file.tpl, how do I determine if $var was passed in?
thanks, |
|
Back to top |
|
t-rob Smarty Rookie
Joined: 22 Feb 2006 Posts: 9 Location: Amsterdam, the Netherlands
|
Posted: Mon Apr 24, 2006 10:39 am Post subject: |
|
|
{if $var}{include file='file.tpl'} {/if} |
|
Back to top |
|
powerobject Smarty Rookie
Joined: 14 Jan 2006 Posts: 18
|
Posted: Mon Apr 24, 2006 2:21 pm Post subject: |
|
|
Oops! I meant including another template and 'optionally' passing a variable into the included template to differ its behavior. Eg:
main.tpl:
----------
situation 1: {include file='file.tpl' var='value'}
situation 2: {include file='file.tpl'}
As per your reply, the following equivalent to isset() inside file.tpl:
file.tpl:
--------
{if $var}
do stuff...
{/if}
But doing {if $var} inside file.tpl is not being equivalent to isset($var) !! When I code two lines including the file.tpl differently as above, I get an error in situation 2 stating:
Undefined index: var
So, how do I determine if a variable is passed and set using the templating language and without using PHP? Any thoughts? |
|
Back to top |
|
TGKnIght Smarty Junkie
Joined: 07 Sep 2005 Posts: 580 Location: Philadelphia, PA
|
|
Back to top |
|
powerobject Smarty Rookie
Joined: 14 Jan 2006 Posts: 18
|
Posted: Mon Apr 24, 2006 5:48 pm Post subject: |
|
|
Is using isset() not equivalent to invoking PHP from within a template? I cannot use PHP inside the template because of some corporate guidelines.
There seems to be no equivalent of isset() in Smarty language other than by using the default modifier to get a default value. But the isset() function does not have a default value argument.
On the other hand, I notice that <td>'s inserted in the included templates are messing my layout (inserting a new column in addition to the existing columns and thereby moving the existing columns to the right):
main.tpl
---------
situation 1: {include file='test.tpl' colspan=3}
situation 2: {include file='test.tpl}
test.tpl
--------
{if $colspan|default:0 > 0} {*situation 1*}
<td colspan="$colspan"}
{/if}
do stuff...
{if $colspan|default:0 > 0}
</td>
{/if}
In situation 1 above, the layout is not the same as if I have to just put the <td>'s inside the main.tpl. And I don't know why.
Thanks, anyway. |
|
Back to top |
|
TGKnIght Smarty Junkie
Joined: 07 Sep 2005 Posts: 580 Location: Philadelphia, PA
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|