Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

registerPlugin for function/compiler different result

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Goodwill
Smarty n00b


Joined: 11 Apr 2014
Posts: 1

PostPosted: Fri Apr 11, 2014 1:06 pm    Post subject: registerPlugin for function/compiler different result Reply with quote

Smarty 3.1.18 Smarty.class.php 4828 2014-04-04 23:38:36Z
in code:
Code:
function smarty_concat_css($arg){

    print_r($arg);
}

$smarty->registerPlugin("compiler", "concat_css", "smarty_concat_css");


in template:
Code:
{concat_css add="shortcodes.css"}


result:

Code:
Array
(
    [add] => "shortcodes.css"
)


For the same function using "function" plugin type

Code:
$smarty->registerPlugin("function", "concat_css", "smarty_concat_css");


result:
Code:
Array
(
    [add] => shortcodes.css
)


For these who dont see that, there are quotes around value for compiler plugin type.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5067
Location: Hamburg / Germany

PostPosted: Fri Apr 11, 2014 7:36 pm    Post subject: Reply with quote

This is not a bug.

The parameter passing is different for both cases.
A function plugin is called at run time as a function and the value of the parameters is passed.
{foo bar=$buh}
In this case the value of $buh is passed.

Compiler plugins should return valid PHP code which is inserted into the compiled template.
The passed parameter are in this case strings for insertion in the PHP code. For above example not the value of $buh is passed but the PHP code to access the variable. (its value at compile time would useless)
If you pass a string to a compiler plugin the parameter does include the quotes.
The compiler plugin can so take any parameter and insert its content in the resulting PHP code.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP