|
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 |
TommyD Smarty Rookie
Joined: 20 Feb 2004 Posts: 18
|
Posted: Fri Apr 16, 2004 10:01 am Post subject: Extend {assign var="" value=""} to allow |
|
|
Hey there!
I'd like to be able to do the following within a template file but fail
with loads of smarty compiling errors:
Code: | {assign var="editable" value=`$cond1 eq "yes" and $cond2 eq "no"`} |
I already tried to put the value part in " instead of ` but failed,
also an {eval var="" assign=""} doesn't work here.
I only like to assign the editable variable once and then use it in
several {if $editable} ... {/if} statements.
The only workaround I know for now is to do the evaluation inside the
calling PHP script.
Tommy. _________________ Administrator / Developer on http://www.musicmademe.com
- http://thomaskeller.biz |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Apr 16, 2004 6:37 pm Post subject: Re: Extend {assign var="" value=""} to a |
|
|
TommyD wrote: |
Code: | {assign var="editable" value=`$cond1 eq "yes" and $cond2 eq "no"`} |
|
I wonder what you think that should do.
Perhaps you want this:
Code: |
{if $cond1 eq "yes" and $cond2 eq "no"}
{assign var="editable" value=true}
{else}
{assign var="editable" value=false}
{/if}
|
|
|
Back to top |
|
TommyD Smarty Rookie
Joined: 20 Feb 2004 Posts: 18
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat Apr 17, 2004 8:20 pm Post subject: |
|
|
Unfortunately, the simple math facility in Smarty does not support booleans, so while you could store $cond1 and $cond2 more conveniently as booleans, you still could not do the following:
Code: | {assign var="editable" value=$cond1&~$cond2} |
So, the only option I can think of is to either use a math trick, write a custom modifier to deal with your logic evaluation, or issue the logic in your PHP file and only send fully qualified parameters to your Smarty template.
In the first case, you also set your conditionals to booleans and you do something on the order of:
Code: | {assign var="editable" value=$cond1-$cond2} |
Thus,
if $cond1 == true (1) - $cond2 == false (0) == 1
if $cond1 == true (1) - $cond2 == true (1) == 0
if $cond1 == false (0) - $cond2 == false (0) == 0
if $cond1 == false (0) - $cond2 == true (1) == -1
and $editable == 1 would satisfy your condition.
The other options should be more self-explanatory. Anything more than that I can not think of, I must sadly say.
Good luck! |
|
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
|