Compile plugin
| From: | Linus McCabe | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Compile plugin | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-3721@lists.php.net to get a copy of this message | ||
I have successfully written plugins of the compile type before but none of
those used any arguments. Now that I need variables it does not seem to
work correctly.
In my template I have:
{count var="base_sections"}
My plugin looks like:
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: compiler.count.php
* Type: compiler
* Name: count
* Purpose: Returns the code for count() of a variable
* -------------------------------------------------------------
*/
function smarty_compiler_count($params, &$smarty)
{
echo $params.'<br>';
echo $params['var'].'<br>'; //I've also tried the extract() way
return <<<EOL
echo @count(\${$params['var']});
EOL;
}
?>
The echo statements returns:
var="base_sections"
v
and the compiled template gets:
<?php echo @count($v); ?>
afaik I'm doin it all correct? Seems to me as if the $params is incorrectly
not turned into an array.
/Linus