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

组件化模�

传统�说,应用程�使用模�编程都按这样的方�: 先在PHP程�中,将需�的��都获�到 (�能还会通过数�库获�), 然�实例化Smarty对象,调用assign()�赋值��,并且display()。 好的,我们�看看模�上显示股票的例��。 我们会在程�中收集到股票的数�,然�将数���赋值到模�,并且显示模�。 现在,如果你�以在模�简�地获�到任���的股票数�,�需�担心在�端获�这些数�,�是更好�?

你�以编写一个自定义扩展,�获�内容并且赋值到模�的��。

Example 21.7. 组件化模�

function.load_ticker.php - 文件在 $plugins 目录


<?php

// setup our function for fetching stock data
function fetch_ticker($symbol)
{
   // put logic here that fetches $ticker_info
   // from some ticker resource
   return $ticker_info;
}

function smarty_function_load_ticker($params, $smarty)
{
   // call the function
   $ticker_info = fetch_ticker($params['symbol']);

   // assign template variable
   $smarty->assign($params['assign'], $ticker_info);
}
?>

    

index.tpl


{load_ticker symbol='SMARTY' assign='ticker'}

Stock Name: {$ticker.name} Stock Price: {$ticker.price}

    

�� {include_php}, {include} 和 {php}.

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 9? (Are you human?)

Advertisement