【问题标题】:Reuse mustache.php in mustache.js在 mustache.js 中重用 mustache.php
【发布时间】:2014-04-23 06:20:43
【问题描述】:

我最近开始使用 Mustache,我需要在 JS 中重用 PHP 模板。 虽然我把模板编译成 JS,但有时像这样嵌入模板更方便

<script type="text/template" id="my-tpl">
  {{foo}}
</script><!-- /#my-tpl -->

(然后从 JS 中使用)。

问题从现在开始:由于我是从 Mustache.php 中显示的,{{foo}} 变量已被解析,因此不再可从 JS 获得。我发现的唯一解决方案是为 JS 使用不同的模板标签(例如&lt;% foo %&gt;),但这会阻止语言之间不太可重用。

所以,我的问题是:可以在 mustache 模板中显示 mustache 模板吗?我错过了文档中的某些内容吗?还是根本不可能?

谢谢!

【问题讨论】:

    标签: javascript templates mustache mustache.php


    【解决方案1】:

    您还可以在嵌入模板之前切换到不同的模板标签,然后在完成后返回:

    something awesome with {{ tags }}!
    
    {{=[[[ ]]]=}}
    <script type="text/template" id="my-tpl">
      {{foo}}
    </script>
    [[[={{ }}=]]]
    
    back again with more {{ tags }}!
    

    【讨论】:

    • 简单高效。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-03
    • 2015-11-29
    • 2011-08-27
    相关资源
    最近更新 更多