如何将 PHP smarty 模板与 Vue.js 集成?
How to integrate PHP smarty template with 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>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!'
}
})
Error Message:
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
感谢任何帮助。谢谢
在你的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"}
我正在 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!'
}
})
Error Message:
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
感谢任何帮助。谢谢
在你的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"}