简体   繁体   English

为什么Smarty用&#39;%&gt;代替&#39; <?php echo '%> “; ?&gt;以及如何避免这种情况?

[英]Why does Smarty replace things like '%>' with <?php echo '%>'; ?> and how to avoid this?

Im optimizing a Smarty template and things are looking good but the only thing left is that the resulting cached template is littered with things like <?php echo '%>'; ?> 我正在优化Smarty模板并且事情看起来不错,但唯一剩下的就是生成的缓存模板充满了像<?php echo '%>'; ?> <?php echo '%>'; ?> where it should just have '%>' . <?php echo '%>'; ?>它应该只有'%>'

It does the same for '?>' but that's understandable as it would confuse PHP, does '%>' have the same effect? 它对'?>'也是一样的,但这是可以理解的,因为它会混淆PHP, '%>'会产生相同的效果吗?

Take a look at the asp-tags ini setting: 看一下asp-tags ini设置:

asp_tags boolean asp_tags布尔值

Enables the use of ASP-like <% %> tags in addition to the usual tags. 除了通常的标记之外,还允许使用类似ASP的<%%>标记。 This includes the variable-> value printing shorthand of <%= $value %>. 这包括<%= $ value%>的变量 - >值打印速记。 For more information, see Escaping from HTML. 有关更多信息,请参阅从HTML转义。

In newer php versions this is turned off by default so if smarty changes those i wouldn't be surprised. 在较新的PHP版本中,这是默认关闭,所以如果聪明的改变那些我不会感到惊讶。 (If i understood you correctly) (如果我理解正确的话)

As you point out, it does the same for the more traditional closing tag ?> . 正如您所指出的,对于更传统的结束标记,它也是如此?>

Well, %> is a PHP closing tag too, albeit one disabled by default. 好吧, %>也是一个PHP结束标记,虽然默认情况下禁用了一个。 You'd activate it with asp-tags : 你用asp-tags激活它:

Enables the use of ASP-like <% %> tags in addition to the usual tags. 除了通常的标记之外,还允许使用类似ASP的<%%>标记。 This includes the variable-> value printing shorthand of <%= $value %>. 这包括<%= $ value%>的变量 - >值打印速记。 For more information, see Escaping from HTML. 有关更多信息,请参阅从HTML转义。

Smarty's just being thorough. Smarty刚刚彻底。 Unfortunately, it's not doing a very good job of it. 不幸的是,它并没有做得很好。 Make sure that this is disabled and your problems should go away. 确保禁用此功能,您的问题应该消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM