在Handlebars模板中执行javascript [英] Executing javascript inside Handlebars template

查看:97
本文介绍了在Handlebars模板中执行javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对js模板引擎完全陌生。把手似乎是流行的选择。我不喜欢使用条件,循环等语法,但是因为我完全有能力并且感觉使用普通的老式js更舒服,我不打算让任何不知道js的人触摸我的模板,我在问Handlebars是否支持这一点。



当然,最流行的选择并不总是最好的。我更像是一个Mootools家伙,jQuery让我疯狂(伟大的图书馆,不适合我)。因此,如果Handlebars是模板引擎的jQuery,那么Mootools会是什么?解析方案

处理栏和 mustache 他们是 逻辑无关。他们现在不能,也不会 允许或推荐您在您的模板中嵌入原始JS。有人说这是一个更好的设计。如果你想嵌入JavaScript,几乎所有其他传统的模板引擎,如 _.template 翡翠 EJS 基于(或至少支持)嵌入式JS代码片段的想法。


I'm totally new to js template engines. Handlebars seems to be the popular choice. I don't dislike the syntax for doing conditions, loops and so on, but since I'm perfectly capable of and feel more comfortable using plain old js and I'm not planning to let anyone who doesn't know js touch my templates, I'm asking if Handlebars supports this.

Of course the most popular choice isn't always the best. I'm more of a Mootools guy and jQuery drives me crazy(great library, just not for me). So if Handlebars was jQuery of template engines, what would be Mootools?

解决方案

One of the central ideas behind handlebars and mustache is they are LOGICLESS by design and intention. They can not now, nor will the ever allow or recommend you embed raw JS in your templates. Some say this is a better design. If you want embedded javascript, almost every other traditional templating engine, such as _.template or jade or EJS is based on (or at least supports) the idea of embedded JS code snippets.

这篇关于在Handlebars模板中执行javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆