Re: Intelligent JavaScript handling
| From: | Justin Patrin | Date: | Wed, 17 Mar 2004 17:57:26 +0000 |
| Subject: | Re: Intelligent JavaScript handling | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-2218@lists.php.net to get a copy of this message | ||
Mark Rogers wrote:
The issue of intelligent JavaScript / CSS handling keeps coming up - there
must be a better way to do it than dropping into and out of
{literal}{/literal} blocks.
I've not played with filters so I'll make a couple of suggestions first and
then have a crack at producing something useful if someone can point me in
the right direction.
It strikes me that what we need is to handle something like:
{script}
function somefunc() {
{if $x==$y}
var x = {$y};
{/if}
}
{/script}
For this to work, the main criteria inside the {script}{/script} block is
that { followed by whitespace, or } preceded by it, should be handled
literally, otherwise it should be seen as Smarty code.
This would seem a reasonable compromise; the braces do not *need* to be
surrounded by whitespace to make them valid JavaScript/CSS, but could be in
order to distinguish them from Smarty code. Likewise, I assume that
whitespace is not illegal in Smarty tags (correct?) but I'd sacrifice that
to make script handling easier.
Are there any obvious problems with this? What is the correct place to
implement it? I guess a pre-filter which turns braces accompanied by
whitespace to (eg) {literal}{{/literal}?
If this is too much of a problem, your best bet it to change your Smarty tags to be something else, say {{ }} which aren't likely to be in JS or CSS. Changing the tag is extremely easy and wouldn't need any extra preprocessing or filtering or another Smarty tag to look for.
--
paperCrane <Justin Patrin>