Re: Re: Intelligent JavaScript handling

Justin Patrin <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
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>

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