Intelligent JavaScript handling

"Mark Rogers" <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Organization Quarella Ltd
Message-ID <018b01c40c3c$b74d6410$1100000a@mark>
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}?

-- 
Mark Rogers,
More Solutions Ltd :: Tel: 0845 45 89 555

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.