{literal}

{literal}可以让一个模板区域的字符原样输出。 这经常用于保护页面上的Javascript或css样式表,避免因为Smarty的定界符{语法}而错被解析。 在{literal}{/literal}内的任何标签都不会被解析,原样输出。 所以如果你有需要放到{literal}内的标签,首先可以考虑是否用 {ldelim}{rdelim} 来代替定界符在页面上的显示(不用{literal})。

Note

因为Smarty会忽略那些带空格的定界符,所以通常不需要使用{literal}{/literal},。 请确定你的Javascript或者CSS样式表的大括号周围是有空格的。这是Smarty 3的新特性。


Example 7.59. {literal} 标签

  1. <script>
  2. // the following braces are ignored by Smarty
  3. // since they are surrounded by whitespace
  4. function myFoo {
  5. alert('Foo!');
  6. }
  7. // this one will need literal escapement
  8. {literal}
  9. function myBar {alert('Bar!');}
  10. {/literal}
  11. </script>
  12.  

参见 {ldelim} {rdelim}避免Smarty解析

原文: https://www.smarty.net/docs/zh_CN/language.function.literal.tpl