|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
RGordijn Smarty Rookie
Joined: 21 Jan 2008 Posts: 15
|
Posted: Mon Jan 21, 2008 8:34 am Post subject: Smarty template syntax check |
|
|
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 |
|
Celeb Administrator
Joined: 17 Apr 2007 Posts: 1025 Location: Vienna
|
Posted: Mon Jan 21, 2008 9:55 am Post subject: |
|
|
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 |
|
RGordijn Smarty Rookie
Joined: 21 Jan 2008 Posts: 15
|
Posted: Mon Jan 21, 2008 1:38 pm Post subject: |
|
|
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 |
|
Celeb Administrator
Joined: 17 Apr 2007 Posts: 1025 Location: Vienna
|
Posted: Mon Jan 21, 2008 1:54 pm Post subject: |
|
|
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 |
|
RGordijn Smarty Rookie
Joined: 21 Jan 2008 Posts: 15
|
Posted: Fri Jan 25, 2008 10:37 am Post subject: |
|
|
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 |
|
|
|
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
|