在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>Test Heading</h2>
{{ message }}
</div>
</div>
</div>
{include file="partials/footer.tpl"}
footer.tpl
<script src="https://unpkg.com/vue"></script>
<script src="resource/js/app.js"></script>
app.js
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
错误讯息:
Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "file:\resource\html\templates\home.tpl" on line 11 "{{ message }}" - Unexpected "{ " <-- thrown in vendor\smarty\smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php on line 11
感谢任何帮助。感谢
答案 0 :(得分:12)
在app.js
使用delimiters
var app = new Vue({
delimiters: ['%%', '%%'],
el: '#app',
data: {
message: 'Hello 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>Test Heading</h2>
%% message %%
</div>
</div>
</div>
{include file="partials/footer.tpl"}