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

字符串资�

Smarty�使用string: 或 eval:的资�类型, �从一个字符串中获得模�内容。

  • string:资æº�看起æ�¥å’Œæ–‡ä»¶æ¨¡æ�¿å·®ä¸�多。 字符串资æº�将被编译并存储æˆ�编译代ç �文件,以供é‡�用。 æ¯�个独立的模æ�¿å­—符串将创建一个新的编译文件。 如果你的模æ�¿å­—符串被ç»�常存å�–,这是一个好的选择。 如果你的模æ�¿å­—符串ç»�常被修改(或者字符串很少机会被é‡�用), 那么使用eval:是一个更好的选择, 因为它ä¸�会ä¿�存编译文件到ç£�盘。

  • eval:资æº�在æ¯�次页é�¢æ¸²æŸ“的时候都会è¿�行。 当字符串ä¸�常é‡�用的情况下,这是一个好的选择。 如果å�Œæ ·çš„字符串ç»�常被存å�–,那么string:会是一个更好的选择。

Note

使用string:的资�,�个字符串都会生�一个编译文件。 Smarty无法检查一个字符串是�已修改,所以�能为�个独立的字符串都生�一个新的编译文件。 选择一个好的资�类型是很��的,���你的�盘塞满浪费的编译文件。

Example 16.5. 使用字符串资�


<?php
$smarty->assign('foo','value');
$template_string = 'display {$foo} here';
$smarty->display('string:'.$template_string); // 下次使用时编译
$smarty->display('eval:'.$template_string); // �次都编译
?>

  

在模�内使用


{include file="string:$template_string"} {* 下次使用时编译 *}
{include file="eval:$template_string"} {* �次都编译 *}


  

string: 和 eval:的资�都�以通过 urlencode() 或 base64_encode() �进行编�。 通常情况下编�是�需�的,但当和扩展模�资� 一起使用的时候,那么就需�进行编�了。

Example 16.6. 使用编��的字符串资�

 
 <?php
 $smarty->assign('foo','value');
 $template_string_urlencode = urlencode('display {$foo} here');
 $template_string_base64 = base64_encode('display {$foo} here');
 $smarty->display('eval:urlencode:'.$template_string_urlencode); // 将通过 urldecode() 解�
 $smarty->display('eval:base64:'.$template_string_base64); // 将通过 base64_decode() 解�
 ?>
 
   

在模�内使用

 
 {include file="string:urlencode:$template_string_urlencode"} {* 将通过 urldecode() 解� *}
 {include file="eval:base64:$template_string_base64"} {* 将通过 base64_decode() 解� *}

 
   

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 2 plus 18? (Are you human?)

Advertisement