【发布时间】:2015-03-11 17:09:10
【问题描述】:
我正在使用 Laravel,我所有的模板都使用 Blade 模板。页面的某些部分需要在服务器端和 JavaScript 进行渲染。对于这些,我使用 Mustache 模板(使用 mustache-l4)。
问题是如何让 Laravel 渲染模板,同时在页面中包含完整的 Mustache 标签,以便 JS 拾取。
例如,如果我有一个像这样的(简化示例)Blade 模板:
<html>
<head></head>
<body>
<h1>{{ $pageTitle }}</h1>
@include('partials/'.$partialName, array('some_text' => $pageText))
<script type="text/mustache">
@include('partials/'.$partialName)
</script>
</body>
</html>
其中包括像这样的.mustache 部分:
{{#some_text}}
<p>{{some_text}}</p>
{{/some_text}}
Mustache 部分在页面加载时呈现良好。但是当它包含在<script></script> 标签之间时,我希望它被逐字呈现。即,{{#some_text}} Mustache 标签应该在呈现的 HTML 中。然后 JavaScript 可以将其作为 Mustache 模板读入。
我可以看到 changing the tag delimiters on the server-side (Blade) templates 可能会实现这一点,但在现阶段,由于许多 Blade 模板已经在工作,我宁愿不这样做。
我不知道该怎么做。我可以只在其中一次包含的时候更改 Mustache 定界符,所以它只会在那时完全呈现吗?
【问题讨论】:
标签: php templates laravel mustache blade