Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
Amazing issue with modifier - comparision fails

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 419
Location: Kathmandu, Nepal

PostPosted: Thu Feb 23, 2012 2:42 pm    Post subject: Amazing issue with modifier - comparision fails Reply with quote

Code:

/**
* HTML PRE writing
*/
function smarty_modifier_pre($html='', $nl2br='N')
{
   if($nl2br=='Y' || $nl2br==true)
   {
      return nl2br($html);
   }
   else
   {
      return '<pre>'.$html.'</pre>';
   }
}


I am sure there is nothing wrong with my plugin.
But when I use the following template code, I get the results of nl2br(), instead of <pre>...</pre>.

Code:
{$identifiers.identifier_sql|pre}


When I compare the true with tripple equals, it is ok, === as:
... if($nl2br=='Y' || $nl2br===true) ...

Did I mistake anything logically?
_________________
Skype: pbimal
To hire instantly as a freelancer - https://www.odesk.com/o/profiles/users/_~~657b70cc7f2c616a/
Visit my website - http://bimal.org.np/ for more articles
800+ screenshots to learn about website mistakes: http://mistakes.sanjaal.com/
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 521

PostPosted: Thu Feb 23, 2012 2:47 pm    Post subject: Re: Amazing issue with modifier - comparision fails Reply with quote

I think 'N' == true.

also

Code:

if ('N')
 echo "true";


would output "true".

Why not just use true and false instead of 'Y' and 'N'?
Back to top
View user's profile Send private message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 419
Location: Kathmandu, Nepal

PostPosted: Thu Feb 23, 2012 2:51 pm    Post subject: PHP Error? Yes it is. Reply with quote

Ok, thanks for figuring it out, it is a PHP error.

Reasons for Y/N: It will come from the database along with the |pre call.
Code:
{...|pre:$yn}


Thanks ...
_________________
Skype: pbimal
To hire instantly as a freelancer - https://www.odesk.com/o/profiles/users/_~~657b70cc7f2c616a/
Visit my website - http://bimal.org.np/ for more articles
800+ screenshots to learn about website mistakes: http://mistakes.sanjaal.com/
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    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