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

Handling of {if tags in Smarty 3

 
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 -> Smarty 3
View previous topic :: View next topic  
Author Message
Aryos
Smarty Rookie


Joined: 12 Jan 2010
Posts: 8

PostPosted: Tue Jan 12, 2010 11:21 am    Post subject: Handling of {if tags in Smarty 3 Reply with quote

Just a small nuisance (not a bug), but would be convenient to fix it.

In Smarty 2, syntax of {if tags like:

Code:
{ if...


works

In Smarty 3, this raises an exception

Notice the extra space character between "{" and "if". Normally, it would not be good for this to work, because this is not the appropriate syntax, however it would be handy for backwards compatibility with Smarty 2, because I'm sure quite a few people, here and there, may have this syntax "error" in old, Smarty 2 templates.
Back to top
View user's profile Send private message
grmbl
Smarty Rookie


Joined: 12 Jan 2010
Posts: 7

PostPosted: Tue Jan 12, 2010 11:56 am    Post subject: Reply with quote

I think it takes like 15 minutes to fix wrong templates with mass search and replace.

PHP was aimed to be backwards-compatible with crappy coding practices - look at the mess it is now.
Back to top
View user's profile Send private message
Aryos
Smarty Rookie


Joined: 12 Jan 2010
Posts: 8

PostPosted: Tue Jan 12, 2010 12:44 pm    Post subject: Reply with quote

More like half a minute Smile
This is not a request for me, I just thought there would be some people not knowing what's wrong when they see this exception message, thus not able to fix it right away.
Back to top
View user's profile Send private message
ChrisFah
Smarty Pro


Joined: 02 Nov 2009
Posts: 159
Location: Traun, Austria

PostPosted: Tue Jan 12, 2010 12:45 pm    Post subject: Reply with quote

I also think:
Better change template than code becuse of this tiny fact.
Regards, Chris
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jan 12, 2010 3:26 pm    Post subject: Reply with quote

Smarty 3 raises an exception because { and } tags with whitespace are ignored so you don't have to escape javacript/css. So when you do this:

{ if foo}

Smarty see it as

if foo}

(no opening tag) and throws the exception. This is a small nuance of Smarty 3, but rids the need for {literal} tags all over the place. You can also revert the behavior with $smarty->auto_literal = false.
Back to top
View user's profile Send private message Visit poster's website
Aryos
Smarty Rookie


Joined: 12 Jan 2010
Posts: 8

PostPosted: Tue Jan 12, 2010 5:49 pm    Post subject: Reply with quote

Thanks for the feedback, this makes sense.
One thing I'd like to ask is if the "auto-literal" function makes execution times any faster or if it's added just for convenience in coding templates.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jan 12, 2010 7:22 pm    Post subject: Reply with quote

I doubt there is any significant difference in performance, its just a change in how templates are compiled.
Back to top
View user's profile Send private message Visit poster's website
Michael White
Smarty Rookie


Joined: 08 Oct 2009
Posts: 20

PostPosted: Thu Jan 14, 2010 5:46 am    Post subject: Reply with quote

This error is present in many of our templates. However, I think that being able to drop {literal} is such a bonus that we'll just fix the templates.
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 -> Smarty 3 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