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

Graceful Error Handling (i.e. when missing plugins)

 
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
mankyd
Smarty Regular


Joined: 04 May 2006
Posts: 92
Location: Boston MA

PostPosted: Mon Jan 08, 2007 6:10 pm    Post subject: Graceful Error Handling (i.e. when missing plugins) Reply with quote

I first want to say that I am loving Smarty and am in the process of a creating what I think will be a great tool that would not otherwise be possible with out it. Thanks to the Smarty team!

Anyways, the tool I am developing is a modular CMS of sorts. At run time, my code loads in a bunch of plugins (one of which is a Smarty based template engine) and those plugins in turn work their magic. Some of those plugins contain within themselves Smarty plugins. One such example is my 'comments' plugin which registers a block plugin with Smarty and loads in comments into the appropriate place and format in the template.

Here's where the problem lies. If the template contains the {comments}{/commments} tag and the plugin is loaded, everything works just peachy. However, if my comments plugin is not loaded (and thus the smarty plugin was not loaded) it fails pretty hard.

I would love it if there was a way to make smarty simply ignore the unrecognized tags. Even better, if it detected it was a block function, it would hide all the html that occurs between the unrecognized tags.

At the very least, I am hoping there is a way to customize the error output and continue on with the script output. Anyone have any ideas?

example template:
Code:

<!-- here is the top part of the page -->
<!-- various content and smarty tags go up here -->

{comments}
<!-- here is a custom block plugin that loops to display comments -->
<!-- it works fine if the comments plugin is loaded, but fails hard if not -->
{/comments}

<!-- more stuff after the comments -->
Back to top
View user's profile Send private message
mankyd
Smarty Regular


Joined: 04 May 2006
Posts: 92
Location: Boston MA

PostPosted: Tue Jan 09, 2007 11:08 pm    Post subject: Reply with quote

So, I think I've figured out how to do this with a prefilter plugin, assuming two things. First, Is there a way to get a list of registered plugins and their type? Second, is there an appropriate way to clear the compile_dir (as opposed to the cache_dir)?

I suppose I can hack through Smarty.class.php to answer the first question, but didn't know if someone else knew the right way to do this. Any help would be appreciated. Thanks!
Back to top
View user's profile Send private message
Pap
Smarty Regular


Joined: 21 Jun 2006
Posts: 69
Location: Denver, CO

PostPosted: Thu Jan 11, 2007 6:48 am    Post subject: Reply with quote

About your first post:

http://smarty.php.net/manual/en/variable.error.reporting.php

You can also pre-register anything you want:
http://smarty.php.net/manual/en/api.register.function.php



About your second post:

http://smarty.php.net/manual/en/api.clear.compiled.tpl.php
http://smarty.php.net/manual/en/variable.compile.id.php
Also, don't forget about the optional [compile_id] parameter when caching templates.



Failing all that, you can do anything by opening up {php}{/php} tags in your templates, but I certainly wouldn't recommend it in a CMS, nor should it be necessary. I think you should rethink some of your design before you do that.
_________________
Don't be stupid, be a Smarty™.
Come and join the P-H-Party.
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