Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Equivalent of isset()

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
powerobject
Smarty Rookie


Joined: 14 Jan 2006
Posts: 18

PostPosted: Mon Apr 24, 2006 9:39 am    Post subject: Equivalent of isset() Reply with quote

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
View user's profile Send private message
t-rob
Smarty Rookie


Joined: 22 Feb 2006
Posts: 9
Location: Amsterdam, the Netherlands

PostPosted: Mon Apr 24, 2006 10:39 am    Post subject: Reply with quote

{if $var}{include file='file.tpl'} {/if}
Back to top
View user's profile Send private message Visit poster's website
powerobject
Smarty Rookie


Joined: 14 Jan 2006
Posts: 18

PostPosted: Mon Apr 24, 2006 2:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Mon Apr 24, 2006 2:35 pm    Post subject: Reply with quote

{if isset($var)}{/if}

or just output it and default it

{$var|default:"My Default Value"}
_________________
Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template
Back to top
View user's profile Send private message Visit poster's website
powerobject
Smarty Rookie


Joined: 14 Jan 2006
Posts: 18

PostPosted: Mon Apr 24, 2006 5:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Mon Apr 24, 2006 7:34 pm    Post subject: Reply with quote

AFAIK even with security enabled you are still able to use certain PHP functions in your if statements..

Take a look at mohrt's response in this post

http://www.phpinsider.com/smarty-forum/viewtopic.php?t=7207&highlight=
_________________
Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP