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解�

有时候部分模�中的代�是�需�或者�希望被Smarty解�的, 比较典型的例�是嵌入在页�HTML中的Javascript或CSS代�。 问题通常�生在这些语言会�常使用{ 和 },但{ 和 }也�好是Smarty的 定界符。

Note

��被解�的一个良好方�,是分离你的Javascript/CSS代�到�独的文件中, 然�在HTML中引入它们。而且这样也有利于�览器进行缓存。 当你需�嵌入Smarty的��或者函数到Javascript/CSS中,请�考下�的方�:

Smarty模�中,当{ 和 }定界符两边都是空格的时候,将会被自动忽略解�。 此特性�以通过设置Smarty的�员�� $auto_literal为false�关闭。

Example 3.8. 使用自动忽略解�的特性


<script>
   // 下�的定界符两边都是空格,所以�以被自动忽略解�
   function foobar {
	alert('foobar!');
   }
   // 下�需�手动忽略解�
   {literal}
	function bazzy {alert('foobar!');}
   {/literal}
</script>
  
 

{literal}..{/literal}�以让�中间的内容忽略Smarty的解�。 在需�使用定界符的时候,�以通过 {ldelim},{rdelim}标签,或者 {$smarty.ldelim},{$smarty.rdelim}的���使用。

Smarty的默认定界符{ 和 }�以整�地界定一般内容的显示。 然而你�以通过修改Smarty的 $left_delimiter 和 $right_delimiter 的��值,设置更适�的定界符。

Note

修改定界符会影�到全部模�代�和解�,请确�在修改�已清除了全部的缓存和编译文件。

Example 3.9. 改�定界符的例�


<?php

$smarty->left_delimiter = '<!--{';
$smarty->right_delimiter = '}-->';

$smarty->assign('foo', 'bar');
$smarty->assign('name', 'Albert');
$smarty->display('example.tpl');

?>

  

模�:


Welcome <!--{$name}--> to Smarty
<script language="javascript">
  var foo = <!--{$foo}-->;
  function dosomething() {
    alert("foo is " + foo);
  }
  dosomething();
</script>

  

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

Advertisement