|
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 |
programmining Smarty Rookie
Joined: 18 Oct 2012 Posts: 6
|
Posted: Thu Sep 19, 2013 10:36 pm Post subject: String comparison {if $var == 'Specific'} not working for me |
|
|
I am probably missing something here, but I've been searching long enough for an answer...
A variable, let's call it $var is passed into the template.
Outputting $var displays the text "Specific" on the page and it has no white spaces around it (it's not between strip tags either)
The problem is that when I want to test the variable for that very specific text and capitalization it is not returning true, which is confusing for me because I thought I was using this right...
What am I missing here?
{if $var == 'Specific'}
{$var == 'Something New'}
{else}
{$var == $var|cat:" Appended"}
{/if} |
|
Back to top |
|
programmining Smarty Rookie
Joined: 18 Oct 2012 Posts: 6
|
Posted: Thu Sep 19, 2013 10:40 pm Post subject: |
|
|
I checked subsequent templates that this variable is passed to (and eventually output) - the text is never stripped, and yet there are no extra characters output to the page...
I'm still very confused as to why or how this could happen, but this is what I used to resolve the issue:
http://www.smarty.net/docsv2/en/language.modifier.strip.tpl
Just before the if statement added:
{$var|strip:''} |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Sep 19, 2013 11:33 pm Post subject: |
|
|
You did not assign new values to $var. your code should be
Code: | {if $var == 'Specific'}
{$var = 'Something New'}
{else}
{$var = $var|cat:" Appended"}
{/if} |
|
|
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
|