Have encountered such a problem in learning Smarty
In the php file I wrote this
Function Demo ($params) { extract ($params); echo $a. $b; } $tpl->registerplugin (' Block ', ' demo ', ' demo ');
Then write this in the template file:
<{demo a=1 b=text}> <{/demo}>
How to Output two x 1text 1text
To solve!
Reply to discussion (solution)
Remove this "<{/demo}>"?
If you get rid of it, there will be an error.
Wood has written plugins, is this example helpful?
http://www.xuandun.net/173/
I saw that.
That's exactly what I wrote.
Oh, I'll try.
Smarty 3.1.7 Example No problem
$smarty = new Smarty; $smarty->registerplugin ("function", "Demo", "Demotest");; /development type, here is the function call, specify the template function name and PHP function name function demotest ($params) {extract ($params);//Get the parameters A and B echo $a. $b;//Output}
{Demo a= "2" b= "Test"}
$smarty->registerplugin ("function", "Demo", "Demotest")
Yes, no problem.
I'm talking about it.
$smarty->registerplugin ("Block", "demo", "Demotest")
Try again.
The problem is still unresolved.
You look at the example in the manual
function Declarationfunction do_translation ($params, $content, $smarty, & $repeat, $template) { if (isset ($ Content) { $lang = $params ["Lang"]; Do some translation with $content return $translation; }} Register with Smarty$smarty->registerplugin ("block", "translate", "do_translation");
{Translate lang= "BR"} Hello, world!. {/translate}
The problem is still unresolved.
The block's plug-in is estimated to be called two times
Example I saw an example or an error occurred
Example I saw an example or an error occurred
Block mode will be executed two times. Through if (Isset ($content)) {, made a judgment so only once.
Http://www.itlearner.com/code/smarty_cn/plugins.block.functions.html
Reference 11 Floor To_phper's reply:
Example I saw an example or an error occurred
Block mode will be executed two times. Through if (Isset ($content)) {, made a judgment so only once.
Http://www.itlearner.com/code/smarty_cn/plugins.block.functions.html
3q problem solved!!
Block will appear two times, the Smarty is a bug it. But does not affect the use.
function Test2 ($arr, $content) {print_r ($arr);//$html = "". $content. ""; /return $html;} $smarty->registerplugin ("block", "Test2", "test2");
<{test2 size= "color=" #ff0000 "}>hello world<{/test2}>
Output:
Array ([size] = [color] + #ff0000) array ([size] = [color] = + #ff0000)