如何将 PHP smarty 模板与 Vue.js 集成? [英] How to integrate PHP smarty template with Vue.js?
本文介绍了如何将 PHP smarty 模板与 Vue.js 集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 PHP 中的 Smarty 模板引擎并希望将 VUE.js 集成到我的应用程序中,但似乎 Smarty 不理解 Vue.js 语法(双花括号)
代码如下:
<块引用>home.tpl
{include file="partials/header.tpl" title="Home"}<body data-spy="scroll" data-target=".navbar"><div class="se-pre-con"></div>{include file="partials/navbar.tpl"}<div class="container container-body"><div class="row"><div class="col-md-12" id="app"><h2>测试标题</h2>{{ 信息 }}
{include file="partials/footer.tpl"}
<块引用>
footer.tpl
<script src="resource/js/app.js"></script>
<块引用>
app.js
var app = new Vue({el: '#app',数据: {消息:你好,Vue!"}})
<块引用>
错误信息:
致命错误:未捕获 -->Smarty 编译器:第 11 行模板file:\resource\html\templates\home.tpl"中的语法错误{{ message }}" - 意外的{" <-- throw in vendor\smarty\smarty\libs\第 11 行的 sysplugins\smarty_internal_templatecompilerbase.php
感谢任何帮助.谢谢
解决方案
在你的 app.js
中使用 delimiters
var app = new Vue({分隔符:['%%', '%%'],el: '#app',数据: {消息:你好,Vue!"},});
然后在 home.tpl
中用 %%
message
{include file="partials/header.tpl" title="Home"}<body data-spy="scroll" data-target=".navbar"><div class="se-pre-con"></div>{include file="partials/navbar.tpl"}<div class="container container-body"><div class="row"><div class="col-md-12" id="app"><h2>测试标题</h2>%% 信息 %%