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