Re: [SMARTY-DEV] Re: Intelligent JavaScript handling

From: Date: Fri, 19 Mar 2004 20:04:06 +0000
Subject: Re: [SMARTY-DEV] Re: Intelligent JavaScript handling
References: 1 2 3 4 5  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2228@lists.php.net to get a copy of this message
Mark Rogers wrote:
Remy writes:
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
Unless I'm missing something this won't handle:
    <style>
        .main {
            color: {$colors.main}
        }
    </style>
.. which is what I'm trying to achieve? (Or similar example in JS; I think the CSS example is simpler to understand.)
If you add this as a prefilter on your smarty templates, it should do what everyone seems to be wanting. Note: this assumes you use {literal-var} as your special smarty tag. If you want something else, just change the regular expression. $text = preg_replace('/{literal-var}(.*?)({\$[^}]*})(.*?){\/literal-var}/s',
             '{literal}\1{/literal}\2{literal}\3{/literal}',
             $text);
-- paperCrane <Justin Patrin>

« previous php.smarty.dev (#2228) next »