Php 奇怪标签内的代码 <# #>

Php code inside of strange Tags <# #>

我目前正在开发一个使用 OnePress 主题的 Wordpress 页面 (Link)。在 customizer-controls.php 文件中,我发现了这个:

<div class="widget-content">
    <# var cond_v; #>
    <# for ( i in data ) { #>
    <# if ( ! data.hasOwnProperty( i ) ) continue; #>
    <# field = data[i]; #>
    <# if ( ! field.type ) continue; #>
...

它看起来像正常的 php 逻辑,但在这个奇怪的标签 <# #> 里面。谁能告诉我这是什么?

它是 Underscore JS 代码,但使用受 Mustache 启发的语法进行标记。

这是因为启用 asp_tags 时,Underscore 的默认 ERB 样式模板与 PHP 不兼容。这意味着在 PHP 中使用 <% %> 可能会在某些网站上中断。

有关为什么在 WordPress 中执行此操作的更多信息,请参阅 https://core.trac.wordpress.org/ticket/22344