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

Advanced smarty unassigned error handling

 
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
Haron
Smarty n00b


Joined: 04 Nov 2016
Posts: 3

PostPosted: Fri Nov 04, 2016 1:43 pm    Post subject: Advanced smarty unassigned error handling Reply with quote

Hi fellaz!

I need help for solve these issue. If I use the unassigned variables into template, I get the following errors:

Code:

Undefined index: FOO in long_monstrous_compiled_template_name.tpl.php on line XX
Trying to get property of non-object in in long_monstrous_compiled_template_name.tpl.php on line XX


It is good (maybe). Really, is very ugly and strongly-debuggable errors on big projects.
But, if I doing syntax error (missed $ for example) I get the good "beautiful" compiler error:

Code:

Syntax error in template "file:/path/to/mytemplate.tpl" on line Y "{FOO}" unknown tag "FOO"


It would be cool if I get unassigned template variable errors as compiled errors. Example:

Code:

Variable warning in template "file:/path/to/mytemplate.tpl" on line Y variable {$FOO} is unassigned


or if FOO is undefined array BAR key ({$BAR.FOO})

Code:

Variable warning in  template "file:/path/to/mytemplate.tpl" on line Y undefined index .FOO in {$BAR}


How I realize this on smarty 3, with use only plugin and extesion features? Maybe ready solutions exists?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Nov 04, 2016 3:35 pm    Post subject: Reply with quote

IMO, such occurences shouldn't happen. If you forgot an assignment, it's not a Smarty error. It is your error and you should fix it in your code.

Said that, current practice of converting errors to exceptions is crude and prone to fail. Smarty doing that where applicable, but overall, best leave it alone.
Back to top
View user's profile Send private message
Haron
Smarty n00b


Joined: 04 Nov 2016
Posts: 3

PostPosted: Fri Nov 04, 2016 4:15 pm    Post subject: Reply with quote

I understand that it my error, and not template engine error. But I need that smarty help me to find this errors. Compiled template analysis not always give an answer to this question. This will help me found errors in my code.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Nov 04, 2016 10:04 pm    Post subject: Reply with quote

That would require wrapping every call to variable, function and block in the compiled template with tests and information about mapping between compiled and source versions of the template.
Which doesn't exactly help performance and greatly tax the compilation itself.
But you're welcome to write your own template compilator that do what you want.
Back to top
View user's profile Send private message
Haron
Smarty n00b


Joined: 04 Nov 2016
Posts: 3

PostPosted: Sat Nov 05, 2016 7:40 am    Post subject: Reply with quote

Quote:
That would require wrapping every call to variable, function and block in the compiled template with tests and information about mapping between compiled and source versions of the template.
Which doesn't exactly help performance and greatly tax the compilation itself.


Compiler may do it in non-production mode. Ex. on compilation process only. And "wrapping every call" it is the controversal sentence. Why? Smarty compiler already pass every template strings, and may check the variables assignments in addition to string syntax checking. You mean that this really bad? Of cource not.

And my question asks: What I do this, without the smarty compiler core modifications, only use the plugins or extensions features?

Quote:
But you're welcome to write your own template compilator that do what you want.


Why? Reinventing the wheel? Smarty is the very good template engine, writing new no need.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Nov 05, 2016 1:18 pm    Post subject: Reply with quote

I mean, you can write one for Smarty.
http://www.smarty.net/docs/en/variable.compiler.class.tpl
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