Re: [SMARTY-DEV] nested comments

From: Date: Thu, 11 Dec 2003 10:37:09 +0000
Subject: Re: [SMARTY-DEV] nested comments
References: 1 2 3 4  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-1968@lists.php.net to get a copy of this message
On Thu, Dec 11, 2003 at 01:10:55PM +0300, Konstantin A. Pelepelin wrote: > On Wed, 10 Dec 2003 10:28:21 +0100, Messju Mohr <messju@lammfellpuschen.de> > wrote: > > >of course comments are not the right way the switch parts of the > >template on and of. use {if 0} or the like. > > Sometimes it is very difficult to find appropriate /if when a template has > many nested if's. > Simple syntax highlighting rules can be added to editor when using {* *} > So I use {* *} to switch off parts of template. > I'd like nested comments very much. > Just my 2 cents. > > Konstantin i wrote a prefilter recently to do this, just for fun. it's not tested heavily: feel free to test it. if more people have use for it, we can put it the contrib-section or the wiki or so. greetings messju <?php /** * Smarty comments prefilter plugin * * File: prefilter.comments.php<br> * Type: prefilter<br> * Name: comments<br> * Date: Nov 14, 2003<br> * Purpose: remove inner comment delimiters from the template to * effectivly allow nested comments * @author Messju Mohr <messju@lammfellpuschen.de> * @version 0.1 * @param string (the template's sourcecode) * @param Smarty_Compiler (the compiler) */ function smarty_prefilter_comments($source, $compiler) { $lc = $compiler->left_delimiter . '*'; $rc = '*' . $compiler->right_delimiter; $lcq = preg_quote($lc, '!'); $rcq = preg_quote($rc, '!'); if ($match = preg_split("!({$lcq})|({$rcq})!", $source, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE)) { $level = 0; for ($i=0, $count=count($match); $i<$count; $i++) { switch ($match[$i]) { case $lc: if ($level++ > 0) $match[$i] = ''; break; case $rc: if (--$level > 0) $match[$i] = ''; break; } } $source = implode('', $match); } return $source; } ?>

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