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

Smarty template syntax check

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


Joined: 21 Jan 2008
Posts: 15

PostPosted: Mon Jan 21, 2008 8:34 am    Post subject: Smarty template syntax check Reply with quote

Hi,

I modified the Smartye.class.php a bit:
Code:
    function trigger_error($error_msg, $error_type = E_USER_WARNING)
    {
        //trigger_error("Smarty error: $error_msg", $error_type);
        $this->main = Main::getInstance();
        $this->main->reportError ( 'Smarty : '. $error_msg );
    }


Instead of the trigger_error() I added my own error handling from the singleton class main.
This is working OK for me.

Is there a smarty function that can check the template for correct syntax before I call display() ?
( because I use multiple display()'s, and if the last one give's an error, my own errorReport is messing up the layout...

cheers!
Rob.
Back to top
View user's profile Send private message
Celeb
Administrator


Joined: 17 Apr 2007
Posts: 1025
Location: Vienna

PostPosted: Mon Jan 21, 2008 9:55 am    Post subject: Reply with quote

I'd recommend you extend the existing Smarty Class and override the trigger_error function there. That way you don't have to do it all over again when updating your Smarty version.

Somebody shoot me if I'm wrong, but I don't think there's such a syntax check in Smarty.
_________________
Darn computers always do what I tell them to instead of what I want them to do.
Back to top
View user's profile Send private message
RGordijn
Smarty Rookie


Joined: 21 Jan 2008
Posts: 15

PostPosted: Mon Jan 21, 2008 1:38 pm    Post subject: Reply with quote

Thats a good point u got there celeb, I builded allready into my app.

And I found a way to cover my problem:

First I fecth all the 3 templates with fetch(), When smarty is fetching()-ing and 1 of the tpl is giving an error, a little bool will be set to true.
after the fetching is done I check that bool, if true dont print the fetch() but a nice error page, if false, print the fetch().

It is not listed for a I-have-good-code-award, but it will do he job.
Back to top
View user's profile Send private message
Celeb
Administrator


Joined: 17 Apr 2007
Posts: 1025
Location: Vienna

PostPosted: Mon Jan 21, 2008 1:54 pm    Post subject: Reply with quote

I was thinking of a quite similar approach.
"Collect" all the errors in your custom error handler and present them to the user when and in what way you like after Smarty is done.

I guess the templates you need to be checked are some user made templates? In that case that kind of a sandbox looks acceptable to me, I wouldn't use it for all the templates in an application, though.
_________________
Darn computers always do what I tell them to instead of what I want them to do.
Back to top
View user's profile Send private message
RGordijn
Smarty Rookie


Joined: 21 Jan 2008
Posts: 15

PostPosted: Fri Jan 25, 2008 10:37 am    Post subject: Reply with quote

the templates are indeed from users, admins, etc, en I just wanted to check for error before displaying.

The way I use now works pretty good, so i'll stick to it.
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