Javascript JS和PHP的通用胡须模板
我正在为JS和PHP使用Mustach,我已经为JS创建了一个模板,现在我想在PHP中使用该模板。是否可以重用该模板 有关参考信息,请参见以下代码: JS模板:Javascript JS和PHP的通用胡须模板,javascript,php,mustache,mustache.php,Javascript,Php,Mustache,Mustache.php,我正在为JS和PHP使用Mustach,我已经为JS创建了一个模板,现在我想在PHP中使用该模板。是否可以重用该模板 有关参考信息,请参见以下代码: JS模板: <table class="table table-bordered table-hover table-striped tablesorter"> <thead> <tr> <th class="header">N
<table class="table table-bordered table-hover table-striped tablesorter">
<thead>
<tr>
<th class="header">Name</th>
<th class="header">Email ID</th>
<th class="header">Contact Number</th>
<th class="header">Edit</th>
</tr>
</thead>
<tbody>
<div id="eTableList"></div>
<script id="eList" type="text/template">
<tr>
<td>{{name}}</td>
<td>{{email}}</td>
<td>{{contact_number}}</td>
<td><a href="{{id}}">View/Edit</a></td>
</tr>
</script>
</tbody>
</table>
<table class="table table-bordered table-hover table-striped tablesorter">
<thead>
<tr>
<th class="header">Name</th>
<th class="header">Email ID</th>
<th class="header">Contact Number</th>
<th class="header">Edit</th>
</tr>
</thead>
<tbody id="eTableList">
<tr>
<td>{{name}}</td>
<td>{{email}}</td>
<td>{{contact_number}}</td>
<td><a href="{{id}}">View/Edit</a></td>
</tr>
</tbody>
</table>
名称
电子邮件ID
联系电话
编辑
{{name}}
{{email}}
{{联系电话}
PHP模板:
<table class="table table-bordered table-hover table-striped tablesorter">
<thead>
<tr>
<th class="header">Name</th>
<th class="header">Email ID</th>
<th class="header">Contact Number</th>
<th class="header">Edit</th>
</tr>
</thead>
<tbody>
<div id="eTableList"></div>
<script id="eList" type="text/template">
<tr>
<td>{{name}}</td>
<td>{{email}}</td>
<td>{{contact_number}}</td>
<td><a href="{{id}}">View/Edit</a></td>
</tr>
</script>
</tbody>
</table>
<table class="table table-bordered table-hover table-striped tablesorter">
<thead>
<tr>
<th class="header">Name</th>
<th class="header">Email ID</th>
<th class="header">Contact Number</th>
<th class="header">Edit</th>
</tr>
</thead>
<tbody id="eTableList">
<tr>
<td>{{name}}</td>
<td>{{email}}</td>
<td>{{contact_number}}</td>
<td><a href="{{id}}">View/Edit</a></td>
</tr>
</tbody>
</table>
名称
电子邮件ID
联系电话
编辑
{{name}}
{{email}}
{{联系电话}
这两个模板的输出是相同的,但我使用PHP或JS根据需要调用它们
那么,有没有一种方法可以使用单个模板而不是上述两个模板,这两个模板都可以在调用中使用,即JS和PHP?是的,您可以,因为模板的位置对于服务器端的PHP和客户端的Javascript都是可访问的 您可以将模板文件放在公共访问的子文件夹中,例如:
public
-- index.php
-- assets
-- -- img (your client side images)
-- -- css (your styles)
-- -- templates
-- -- -- my_template.tpl
-- -- js (your javascript)
然后在js脚本中使用它时,从相对路径调用../templates/my_template.tpl,在PHP中,从绝对路径调用,类似于my_ROOT_APP_常量。“资产/模板/my_template.tpl”
希望这对你有帮助
致以最诚挚的问候好的,很酷……但是如何制作通用模板,正如您所看到的,这两个模板都是不同的,一个是php模板,另一个是js模板。