Smarty 3.1.8 in the registration function Registerplugin use problem

Source: Internet
Author: User
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)
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.