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

String comparison {if $var == 'Specific'} not working for me

 
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
programmining
Smarty Rookie


Joined: 18 Oct 2012
Posts: 6

PostPosted: Thu Sep 19, 2013 10:36 pm    Post subject: String comparison {if $var == 'Specific'} not working for me Reply with quote

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


Joined: 18 Oct 2012
Posts: 6

PostPosted: Thu Sep 19, 2013 10:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Sep 19, 2013 11:33 pm    Post subject: Reply with quote

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