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

{include}

{include}鐢ㄤ簬杞藉叆鍏朵粬妯℃澘鍒板綋鍓嶆ā鏉夸腑銆 鍦ㄥ寘鍚ā鏉夸腑鍙敤鐨勫彉閲忥紝杞藉叆鍚庡湪褰撳墠妯℃澘浠嶇劧鍙敤銆

  • {include}蹇呴』璁剧疆file 灞炴э紝璁剧疆杞藉叆鐨勬枃浠惰祫婧愯矾寰勩

  • 璁剧疆浜嗗彲閫夌殑assign灞炴э紝灏{include}妯℃澘鐨勫唴瀹硅祴鍊煎埌鍙橀噺锛岃屽苟闈炶緭鍑恒 涓 {assign}鎿嶄綔鐩镐技銆

  • 鍖呭惈妯℃澘鏃讹紝鍙互鍍忎娇鐢灞炴涓鏍疯缃紶閫掔殑鍙橀噺銆 杩欐牱浼犻掔殑鍙橀噺锛屼綔鐢ㄨ寖鍥翠粎闄愪簬鍖呭惈鐨勬ā鏉垮唴銆 灞炴т紶閫掔殑鍙橀噺灏嗚鐩栧師鍖呭惈妯℃澘鐨勫悓鍚嶅彉閲忋

  • 浣犲彲浠ュ湪褰撳墠妯℃澘鍐呬娇鐢ㄥ寘鍚ā鏉跨殑鍏ㄩ儴鍙橀噺銆 浣嗘槸濡傛灉鍖呭惈妯℃澘鍐呮湁淇敼鎴栬呮柊寤哄彉閲忥紝閭d箞杩欎簺鍙橀噺鍙湁鍖呭惈妯℃澘鐨勪綔鐢ㄨ寖鍥达紝鑰屼笉鍙互鏄綋鍓{include}妯℃澘涓娇鐢ㄣ 杩欑榛樿鐨勮缃紝鍙互閫氳繃鍦ㄥ寘鍚ā鏉挎椂璁剧疆{include}鐨勪綔鐢ㄨ寖鍥村睘鎬э紝鎴栬 鍦ㄤ慨鏀规垨鏂板鍙橀噺鏃堕氳繃{assign}鐨勪綔鐢ㄨ寖鍥村睘鎬ф潵璁惧畾銆 鍚庤呭湪闇瑕佸寘鍚ā鏉胯繑鍥炲兼椂姣旇緝鏈夌敤銆

  • 褰撴枃浠朵笉鍦$template_dir鐩綍涓椂锛 浣跨敤璧勬簮鐨勮娉曟潵{include}鍖呭惈鏂囦欢銆

Attributes:

鍙傛暟鍚嶇О 绫诲瀷 蹇呴夊弬鏁 榛樿鍊 璇存槑
file string Yes n/a 鍖呭惈杞藉叆鐨勬枃浠跺悕
assign string No n/a 灏嗗寘鍚殑鏂囦欢鍐呭璧嬪肩粰鍙橀噺
cache_lifetime integer No n/a 鍗曠嫭寮鍚鍖呭惈妯℃澘鐨勭紦瀛樻椂闂
compile_id string/integer No n/a 鍗曠嫭璁剧疆琚寘鍚ā鏉跨殑缂栬瘧ID
cache_id string/integer No n/a 鍗曠嫭璁剧疆琚寘鍚ā鏉跨殑缂撳瓨ID
scope string No n/a 瀹氫箟琚寘鍚ā鏉跨殑璧嬪煎彉閲忎綔鐢ㄨ寖鍥: 'parent','root' 鎴 'global'
[var ...] [var type] No n/a 浼犻掑埌鍖呭惈妯℃澘鐨勫彉閲

鍙夋爣璁:

鍚嶇О 璇存槑
nocache 鍏抽棴鍖呭惈妯℃澘鐨勭紦瀛
caching 鎵撳紑鍖呭惈妯℃澘鐨勭紦瀛
inline 璁剧疆鎴恡rue鏃讹紝鍦ㄧ紪璇戞椂鎶婂寘鍚ā鏉跨殑鍐呭涔熷悎骞跺埌褰撳墠妯℃澘鐨勭紪璇戞枃浠朵腑銆

Example聽7.46.聽绠鍗 {include} 渚嬪瓙


<html>
<head>
  <title>{$title}</title>
</head>
<body>
{include file='page_header.tpl'}

{* body of template goes here, the $tpl_name variable
   is replaced with a value eg 'contact.tpl'
*}
{include file="$tpl_name.tpl"}

{* using shortform file attribute *}
{include 'page_footer.tpl'}
</body>
</html>

  

Example聽7.47.聽{include} 浼犻掑彉閲


{include 'links.tpl' title='Newest links' links=$link_array}
{* body of template goes here *}
{include 'footer.tpl' foo='bar'}

  

鍖呭惈浜嗕笅闈㈢殑 links.tpl 妯℃澘


<div id="box">
<h3>{$title}{/h3>
<ul>
{foreach from=$links item=l}
.. do stuff  ...
</foreach}
</ul>
</div>


Example聽7.48.聽{include} 浣滅敤鑼冨洿绀轰緥

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


{include 'sub_template.tpl' scope=parent}
...
{* display variables assigned in sub_template *}
{$foo}<br>
{$bar}<br>
...

  

鍖呭惈浜嗕笅闈㈢殑 sub_template.tpl 妯℃澘


...
{assign var=foo value='something'}
{assign var=bar value='value'}
...


Example聽7.49.聽{include} 鍏抽棴缂撳瓨

鍖呭惈妯℃澘灏嗕笉琚紦瀛


{include 'sub_template.tpl' nocache}
...

  

Example聽7.50.聽{include} 鍗曠嫭鐨勭紦瀛樻椂闂

涓嬮潰渚嬪瓙鍖呭惈妯℃澘灏嗗崟鐙缃紦瀛樻椂闂500绉掋


{include 'sub_template.tpl' cache_lifetime=500}
...

  

Example聽7.51.聽{include}寮鍚紦瀛

涓嬮潰鐨勪緥瀛愬寘鍚ā鏉跨殑缂撳瓨灏嗙嫭绔嬩簬鍏ㄥ眬妯℃澘缂撳瓨璁剧疆涔嬪銆


{include 'sub_template.tpl' caching}
...

  

Example聽7.52.聽{include} 鍜岃祴鍊煎彉閲

涓嬮潰鐨勪緥瀛愬皢nav.tpl鐨勫唴瀹硅祴鍊肩粰浜$navbar 鍙橀噺, 璇ュ彉閲忓皢椤甸潰鐨勫ご閮ㄥ拰搴曢儴鏄剧ず銆

 
<body>
  {include 'nav.tpl' assign=navbar}
  {include 'header.tpl' title='Smarty is cool'}
    {$navbar}
    {* body of template goes here *}
    {$navbar}
  {include 'footer.tpl'}
</body>

   

Example聽7.53.聽{include} 鐩稿璺緞

涓嬮潰鐨勪緥瀛愬寘鍚殑妯℃澘鏂囦欢閮芥槸鐩稿褰撳墠妯℃澘鐨勭洰褰曘


   {include 'template-in-a-template_dir-directory.tpl'}
   {include './template-in-same-directory.tpl'}
   {include '../template-in-parent-directory.tpl'}

    

Example聽7.54.聽鍚勭 {include} 璧勬簮渚嬪瓙


{* absolute filepath *}
{include file='/usr/local/include/templates/header.tpl'}

{* absolute filepath (same thing) *}
{include file='file:/usr/local/include/templates/header.tpl'}

{* windows absolute filepath (MUST use "file:" prefix) *}
{include file='file:C:/www/pub/templates/header.tpl'}

{* include from template resource named "db" *}
{include file='db:header.tpl'}

{* include a $variable template - eg $module = 'contacts' *}
{include file="$module.tpl"}

{* wont work as its single quotes ie no variable substitution *}
{include file='$module.tpl'}

{* include a multi $variable template - eg amber/links.view.tpl *}
{include file="$style_dir/$module.$view.tpl"}

  

鍙傝 {include_php}, {insert}, {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 6 plus 2? (Are you human?)

Advertisement