Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Brautkleider auf Topwedding.de

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Shop high quality cheap prom dresses on Dresswe.co.uk

Buy New Arrival Cheap Prom Dresses 2015 at JDBRIDAL Prom Dress Store

Advertisement

�函数

void smarty_block_name( $params,  
  $content,  
  $template,  
  &$repeat);  
array $params;
mixed $content;
object $template;
boolean &$repeat;
 

�函数的形�是:{func} .. {/func}。 ���说,它们用标签圈起一个�,然�对这个�的内容进行�作。 �函数优先于��的自定义函数, 这样,你�能�时有自定义函数{func}和�函数{func}..{/func}。

  • 默认你的函数将被Smarty调用两次,在开始标签ä½�置调用和在结æ�Ÿæ ‡ç­¾ä½�置调用。 (å�‚考下é�¢å¦‚何通过$repeatæ�¥æ”¹å�˜è¿™ç§�情况)

  • 从Smarty 3.1开始,开始标签的返回值将会被显示。

  • å�—函数å�ªæœ‰åœ¨å¼€å§‹æ ‡ç­¾æ—¶æ‰�有 属性。 模æ�¿ä¸­ä¼ é€’ç»™å�—函数的属性都包å�«åœ¨$paramså�‚数数组中。 在处ç�†ç»“æ�Ÿæ ‡ç­¾æ—¶ï¼Œè¿™äº›å±žæ€§ä¹Ÿæ˜¯å�¯ç”¨çš„。

  • $content的值,å�–决于函数在执行开始标签还是结æ�Ÿæ ‡ç­¾ã€‚ 当在开始标签时,它会是nullï¼› 当在结æ�Ÿæ ‡ç­¾æ—¶ï¼Œå®ƒä¼šæ˜¯æ¨¡æ�¿å�—里é�¢å…¨éƒ¨çš„内容。 注æ„�模æ�¿å�—å·²ç»�是被Smarty处ç�†è¿‡çš„,所以你得到的内容是模æ�¿å�—的输出内容,而ä¸�是模æ�¿å�—çš„æº�代ç �。

  • $repeat是一个引用值,能控制å�—å�¯ä»¥è¢«æ˜¾ç¤ºå¤šå°‘次。 当å�—函数被第一次调用时(开始标签),$repeat默认是trueï¼› éš�å�Žçš„调用(结æ�Ÿæ ‡ç­¾ï¼‰éƒ½æ˜¯false。 æ¯�次当å�—函数返回时将$repeat设æˆ�true, {func}...{/func}间的内容会被å†�次计算, 计算结果ä¿�å­˜$contentå�‚数内, 在并且函数将被å†�次执行。

如果使用了嵌套的�函数, �以通过$smarty->_tag_stack���找到父�的函数。 ��对其用一下var_dump() 就�以知�整个层次结构了。

Example 18.5. �函数


<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     block.translate.php
 * Type:     block
 * Name:     translate
 * Purpose:  翻译一�文字
 * -------------------------------------------------------------
 */
function smarty_block_translate($params, $content, Smarty_Internal_Template $template, &$repeat)
{
    // �在结�标签时输出
    if(!$repeat){
        if (isset($content)) {
            $lang = $params['lang'];
			// 翻译$content的内容
            return $translation;
        }
    }
}
?>

     

��: registerPlugin(), unregisterPlugin().

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 3 plus 20? (Are you human?)

Advertisement