|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jebediah Smarty Rookie
Joined: 28 Jan 2012 Posts: 16
|
Posted: Sat Jan 28, 2012 2:28 pm Post subject: smarty compiler function |
|
|
Hello all,
I'm using the newest stable version of Smarty (Smarty 3.1.7), I am using PHP 5.3.5 on an Ubuntu server.
My test code
I've written a simple compiler function in a file called smarty_compiler_action.php.
Code: |
function smarty_compiler_action($params, $smarty){
$action = $params['name'];
return $action;
}
|
I have registered the compiler function like this:
Code: |
include_once 'smarty_compiler_action.php';
$smarty = new Smarty();
$smarty->registerPlugin('compiler', 'action', 'smarty_compiler_action');
$smarty->display('test.tpl');
|
and I have the following template 'test.tpl':
Code: |
This is the return of the compiler function: {action name='my simple test'}
|
The output
Registering the compiler function works perfectly fine and I get the following output:
Code: |
This is the return of the compiler function: 'my simple test'
|
My question
The question I am having is the following: Why are the single quotes included in the parameter value?
I would be expecting the following output:
Code: |
This is the return of the compiler function: my simple test
|
i.e. without the single quotes. Is this intended behavior, i.e. do I have to strip the quotes myself in the compiler function or did I just oversee something?
It's not a problem to strip the quotes, I just wanted to verify that the quotes indeed ARE intended to be included in the parameter value for a compile function. I would like to be compatible with future versions of the awesome Smarty...
Any help/insights/feedback would be more than appreciated!
Thanks and all the bests,
Jeb |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Jan 28, 2012 3:42 pm Post subject: |
|
|
Compiler functions are designed to return PHP code in <?php ... ?> tags for the compiled template. The Parser is designed to pass the parameter in way that they can be included directly in the resulting code. So if you pass a string it does include the quotes. If you pass a variable it does not pass the value but the string which with the variable access code.
If you need a plugin which does not generate PHP code you should use a function plugin and not a compiler plugin. |
|
Back to top |
|
jebediah Smarty Rookie
Joined: 28 Jan 2012 Posts: 16
|
Posted: Sat Jan 28, 2012 3:45 pm Post subject: |
|
|
Hi U.Tews,
thanks a lot for this. I'm indeed trying to implement an include functionality following the functional design principle.
I was just trying to give a minimal example and sorry for not making the example semantic. I appreciate you answer very much!
Thanks a lot for this,
Jeb |
|
Back to top |
|
dslava Smarty n00b
Joined: 07 Jul 2011 Posts: 1 Location: Россия
|
Posted: Wed Feb 15, 2012 12:47 am Post subject: smarty compiler function |
|
|
Hi
One can register smarty functions any time before the smarty output is called...so frontend_header sounds like a suitable register_function call to me?
Is it plugins that you need to define strings in every language, or the main code? I can never remember. |
|
Back to top |
|
|
|
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
|