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

{assign}

{assign}鐢ㄤ簬鍦妯℃澘杩愯鏈熼棿璧嬪肩粰鍙橀噺.

Note

鍦ㄦā鏉夸腑杩涜璧嬪硷紝浠庢牴鏈笂璁茶繕鏄皢绋嬪簭閫昏緫鏀惧埌鏄剧ず灞傛潵杩涜浜嗭紝鍦≒HP绔繘琛屾鎿嶄綔浼氭洿濂姐傝鑷鑰冭檻銆

Note

鍙傝璧嬪肩粰鍙橀噺鏂规硶鐨缂╁啓

灞炴:

鍙傛暟鍚嶇О 绫诲瀷 蹇呴夊弬鏁 榛樿鍊 璇存槑
var string Yes n/a 琚祴鍊肩殑鍙橀噺鍚
value string Yes n/a 璧嬬殑鍊
scope string No n/a 鍙橀噺鐨勪綔鐢ㄨ寖鍥: 'parent','root' 鎴 'global'

鍙夋爣璁:

鍚嶇О 璇存槑
nocache 瀵硅祴鍊兼搷浣滀笉杩涜缂撳瓨

Example聽7.8.聽{assign}


{assign var="name" value="Bob"}
{assign "name" "Bob"} {* short-hand *}

The value of $name is {$name}.

  

杈撳嚭锛


The value of $name is Bob.

  

Example聽7.9.聽{assign} 浣跨敤nocache灞炴


{assign var="name" value="Bob" nocache}
{assign "name" "Bob" nocache} {* short-hand *}

The value of $name is {$name}.

  

杈撳嚭锛


The value of $name is Bob.

  

Example聽7.10.聽{assign} 杩涜鏁板杩愮畻


{assign var=running_total value=$running_total+$some_array[$row].some_value}

  

Example聽7.11.聽{assign} 鍦ㄨ皟鐢ㄧ殑妯℃澘鍐呯殑浣滅敤鑼冨洿

鍦ㄥ寘鍚殑妯℃澘鍐呰祴鍊肩殑鍙橀噺锛屽湪鍖呭惈妯℃澘鍐呭彲瑙併


{include file="sub_template.tpl"}
...
{* display variable assigned in sub_template *}
{$foo}<br>
...

  

涓婇潰鐨勬ā鏉挎槸鍖呭惈浜嗕笅闈㈢殑妯℃澘sub_template.tpl


...
{* foo will be known also in the including template *}
{assign var="foo" value="something" scope=parent}
{* bar is assigned only local in the including template *}
{assign var="bar" value="value"}
...


Example聽7.12.聽{assign} 浣滅敤鑼冨洿渚嬪瓙

璁剧疆鍙橀噺璁块棶鑼冨洿涓簉oot锛岀劧鍚庤鍙橀噺鍦ㄧ浉鍏虫ā鏉块噷闈㈤兘鍙銆


{assign var=foo value="bar" scope="root"}

  

Example聽7.13.聽{assign} 璧嬪间竴涓叏灞鍙橀噺

鍏ㄥ眬鍙橀噺鍦ㄤ换浣曟ā鏉垮唴鍧囧彲瑙併


{assign var=foo value="bar" scope="global"}
{assign "foo" "bar" scope="global"} {* short-hand *}

  

Example聽7.14.聽浠嶱HP鑴氭湰涓幏鍙杮assign} 鐨勫彉閲

鍙互浣跨敤 getTemplateVars()鍦≒HP鑴氭湰涓幏鍙{assign}鐨勫彉閲忓笺 杩欓噷鐨勬ā鏉垮垱寤轰簡鍙橀噺$foo


{assign var="foo" value="Smarty"}

褰撴ā鏉胯鎵ц鏃/鎵ц鍚庯紝鍙互鐢ㄤ互涓嬬殑鏂瑰紡鍦≒HP鑾峰彇鍒拌繖涓ā鏉垮彉閲忋


<?php

// this will output nothing as the template has not been executed
echo $smarty->getTemplateVars('foo');

// fetch the template to a variable
$whole_page = $smarty->fetch('index.tpl');

// this will output 'smarty' as the template has been executed
echo $smarty->getTemplateVars('foo');

$smarty->assign('foo','Even smarter');

// this will output 'Even smarter'
echo $smarty->getTemplateVars('foo');

?>


涓嬮潰鐨勫嚱鏁伴兘鍙敤assign浣滀负鍙灞炴э紝鐢ㄤ簬灏嗗嚱鏁扮粨鏋滆祴鍊肩粰鍙橀噺鑰屼笉鏄剧ず銆

{capture}, {include}, {include_php}, {insert}, {counter}, {cycle}, {eval}, {fetch}, {math}, {textformat}

鍙傝 {$var=...}, assign()getTemplateVars().

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 12 plus 15? (Are you human?)

Advertisement