简体   繁体   中英

smarty php : how to pass variable in registerPlugin function

i want to know how can i pass variable to function which am registering as plugin with registerPlugin() function of smarty php

how am doing.

i have smarty_get_data function

function smarty_get_data($params, Smarty_Internal_Template $template)
{
     // trying to use passed variable 
   echo 'passed var :: '.$params['doma']; 
}

variable which i want to pass

$doma = 'test var';

register as plug-in

$smarty->registerPlugin('function', 'get_data', 'smarty_get_data', false, array('doma' => $doma));

output is blank

passed var ::

so need help what am doing wrong !

You can't pass the $doma into the registerPlugin function. You need to pass it when function get_data is called (in the template).

First register the plugin:

$smarty->registerPlugin('function', 'get_data', 'smarty_get_data', false);

Then in the template call the registered function with data :

{get_data doma="some text"}

Also, please check the documentation of the function here : http://www.smarty.net/docs/en/api.register.plugin.tpl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM