PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.smarty.general > determining syntactically valid templates
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
determining syntactically valid templates

Réponse
 
LinkBack Outils de la discussion
Vieux 04/11/2006, 05h23   #1
Travis Low
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut determining syntactically valid templates

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>
  Réponse avec citation
Vieux 05/11/2006, 21h45   #2
Marcus Bointon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] determining syntactically valid templates

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/
  Réponse avec citation
Vieux 06/11/2006, 02h32   #3
Max Schwanekamp
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [SMARTY] determining syntactically valid templates

> 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

  Réponse avec citation
Vieux 06/11/2006, 11h13   #4
messju mohr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] determining syntactically valid templates

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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h30.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11457 seconds with 12 queries