Re: Re: Intelligent JavaScript handling

Rémy Dufour <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Message-ID <000801c40dbe$f4fb6540$2000000a@rdufour>
Here's a prefilter function i've found and modified a little.
It do the job perfectly for us

function smarty_prefilter_literal_script(&$tpl_source, &$smarty)
{
    // Put {literal}{/literal} tag automaticaly, unless you specify <script
... smarty>...</script>
    $pattern[] = '~<script\b(?![^>]*smarty)(.*)</script>~siU';
    $replace[] = '<!-- {literal} --><script$1 $2</script><!-- 
{/literal} -->';
    return  preg_replace($pattern, $replace, $tpl_source);
}

The same for <style> tags

function smarty_prefilter_literal_style(&$tpl_source, &$smarty)
{
    $pattern[] = '~<style\b(?![^>]*smarty)>(.*)</style>~siU';
    $replace[] = '<!--{literal}--><style$1>$2</style><!--{/literal}-->';
    return  preg_replace($pattern, $replace, $tpl_source);
} // function

Hope it will help you.

Rémy Dufour

-- 
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.