我一直在使用 jTemplates,并尝试完全使用 jQuery + jTemplates + Web Services 来构建一个站点。事情真的很好,直到我偶然发现这样的情况,我需要添加一些服务器控件或需要在模板渲染过程中使用代码块 <%= DoSomething(param) %> 从后面的代码中解析一些数据.
考虑以下 jTemplates 的精简版本:
<script type="text/html" id="ContentTemplates">
{#template MAIN}
{#foreach $T.Products as product}
<div id="div-product-{$T.product.Id}" class="product-wrapper">
{#include Content root=$T.product}
</div>
{#/for}
{#/template MAIN}
{#template Content}
<div class="view-container">
<p>Id: {$T.Id}</p>
<p>Desc: {$T.Desc}</p>
<p>Vendor Id: {$T.VendorId}</p>
<!-- Vendor name doesn't supplied by the web service,
it needs to be resolved using ASP.NET server code -->
<p>Vendor Name: <%= GetVendorName({$T.VendorId}) %></p>
<!-- i was hoping to do something like this,
but apparently it wouldn't work this way -->
</div>
{#/template Content}
</script>
现在我因为未能实现如此简单的事情而将头撞到墙上……这是我错过的事情吗?还是 jTemplates 真的应该只用于呈现简单的 HTML 布局?模板引擎是否能够解析服务器代码块?还是我只是注定要失败?