|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello. Is there a function available, or can anyone think of a good trick to
determine if a template is syntactically valid, without having to render it? I'd like to provide my clients a means to do simple template edits. But before saving the template, I'd like to be able to pass the template as a string to some function (or pass the filename/path to a function) and have the function return TRUE if the template is syntactically valid, FALSE otherwise. cheers, Travis -- Travis Low <mailto:travis@dawnstar.com> <http://www.dawnstar.com> |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 4 Nov 2006, at 04:23, Travis Low wrote:
> Hello. Is there a function available, or can anyone think of a > good trick to determine if a template is syntactically valid, > without having to render it? > > I'd like to provide my clients a means to do simple template > edits. But before saving the template, I'd like to be able to pass > the template as a string to some function (or pass the filename/ > path to a function) and have the function return TRUE if the > template is syntactically valid, FALSE otherwise. I think the only way to do it is to render it in a separate PHP instance as it's quite easy to create a template that causes a fatal error, and there's nothing you can do to trap that within the current PHP instance. So either make a call to a url using file_get_contents or curl, or call it from a command line instance with exec() and friends, then check the output for any error messages. Marcus -- Marcus Bointon Synchromedia Limited: Creators of http://www.smartmessages.net/ marcus@synchromedia.co.uk | http://www.synchromedia.co.uk/ |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
> From: Travis Low
> Hello. Is there a function available, or can anyone think of > a good trick to determine if a template is syntactically > valid, without having to render it? > > I'd like to provide my clients a means to do simple template > edits. But before saving the template, I'd like to be able > to pass the template as a string to some function (or pass > the filename/path to a function) and have the function return > TRUE if the template is syntactically valid, FALSE otherwise. Probably the easiest method would be an iframe. Take the user's edited template, save it as a temp file, use an iframe to make a separate call to the server to get a rendered version, to be displayed via the iframe. Give the user a method on the containing page to accept/revise their edited content. If accepted, issue a request (either via regular post or via in background with an ajax request) to move the temp file to its permanent home. Obviously if the edited template results in a fatal parse error or something, the user will not "accept" the edit. Iframes are generally irritating, but this is one case where it might be worthwhile to 'em. -- Max Schwanekamp NeptuneWebworks.com |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Fri, Nov 03, 2006 at 11:23:59PM -0500, Travis Low wrote:
> Hello. Is there a function available, or can anyone think of a good trick > to determine if a template is syntactically valid, without having to render > it? unfortunately there is no convenient api function for this. maybe you can compile the template like eval does: $smarty->_compile_source('checking template', $source, $php_code) caveats: - compiler-function are executed, of course (this may have undesired side effects) - maybe you should additionally check the php-syntax of $php_code since there may be errors in the template that smarty fails to catch (that should not be, but it happend reguarly) greetins messju > I'd like to provide my clients a means to do simple template edits. But > before saving the template, I'd like to be able to pass the template as a > string to some function (or pass the filename/path to a function) and have > the function return TRUE if the template is syntactically valid, FALSE > otherwise. > > cheers, > > Travis > > -- > Travis Low > <mailto:travis@dawnstar.com> > <http://www.dawnstar.com> > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php |
|
![]() |
| Outils de la discussion | |
|
|