简体   繁体   中英

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 '%>'; ?> <?php echo '%>'; ?> where it should just have '%>' .

It does the same for '?>' but that's understandable as it would confuse PHP, does '%>' have the same effect?

Take a look at the asp-tags ini setting:

asp_tags boolean

Enables the use of ASP-like <% %> tags in addition to the usual tags. This includes the variable-> value printing shorthand of <%= $value %>. For more information, see Escaping from HTML.

In newer php versions this is turned off by default so if smarty changes those i wouldn't be surprised. (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. You'd activate it with asp-tags :

Enables the use of ASP-like <% %> tags in addition to the usual tags. This includes the variable-> value printing shorthand of <%= $value %>. For more information, see Escaping from HTML.

Smarty's just being thorough. Unfortunately, it's not doing a very good job of it. Make sure that this is disabled and your problems should go away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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