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

Name

registerPlugin() 鈥 娉ㄥ唽鎻掍欢

璇存槑

void聽registerPlugin(string聽type,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽string聽name,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽mixed聽callback,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽bool聽cacheable,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽mixed聽cache_attrs);

璇ュ嚱鏁板皢浠ユ彃浠剁殑褰㈠紡鏉ユ敞鍐屽嚱鏁版垨鑰呮柟娉曘 鍙傛暟濡備笅锛

  • type defines the type of the plugin. Valid values are "function", "block", "compiler" and "modifier".

  • name defines the name of the plugin.

  • callback defines the PHP callback. it can be either:

    • A string containing the function name

    • An array of the form array(&$object, $method) with &$object being a reference to an object and $method being a string containing the method-name

    • An array of the form array($class, $method) with $class being the class name and $method being a method of the class.

  • 澶у鏁版儏鍐典笅cacheablecache_attrs鍙鐪佺暐銆 鍙傝缂撳瓨鑳藉姏璁剧疆瀹冧滑鐨勫笺

Example聽14.39.聽娉ㄥ唽鍑芥暟


<?php
$smarty->registerPlugin("function","date_now", "print_current_date");

function print_current_date($params, $smarty)
{
  if(empty($params["format"])) {
    $format = "%b %e, %Y";
  } else {
    $format = $params["format"];
  }
  return strftime($format,time());
}
?>

   

鍦ㄦā鏉夸腑锛


{date_now}

{* 鎴栧畾涔夋椂闂存牸寮 *}
{date_now format="%Y/%m/%d"}


Example聽14.40.聽娉ㄥ唽鍧楀嚱鏁


<?php
// 鍑芥暟瀹氫箟
function do_translation ($params, $content, $smarty, &$repeat, $template)
{
  if (isset($content)) {
    $lang = $params["lang"];
    // 杩欓噷鍙互鏀剧疆缈昏瘧 $content 鐨勪唬鐮
    return $translation;
  }
}

// 娉ㄥ唽鍒癝marty
$smarty->registerPlugin("block","translate", "do_translation");
?>

   

妯℃澘涓細


{translate lang="br"}Hello, world!{/translate}

   

Example聽14.41.聽娉ㄥ唽淇グ鍣


<?php

// 鎴戜滑灏哖HP鐨剆tripslashes鍑芥暟鏄犲皠鎴愪竴涓猄marty鐨勪慨楗板櫒
$smarty->registerPlugin("modifier","ss", "stripslashes");

?>

妯℃澘涓彲浣跨敤ss鏉ヨ繃婊ゅ弽鏂滅嚎銆


<?php
{$var|ss}
?>


鍙傝 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 19 plus 20? (Are you human?)

Advertisement