在 js 页面中使用速度模板引擎 [英] use velocity template engine in js page
问题描述
我知道有一些 nodejs 模块可以在节点中使用 apache 速度,例如 那个问题的回复中的那些地址.
i know there's some nodejs modules to use apache velocity in node like those addresses in that question's response.
可以通过 browserify.js 将其用作胡子替代品吗?
could be done to use it as a, says, mustache replacement via, maybe, browserify.js?
作为工作流程,您将如何做到这一点?
how would you do that as a workflow?
我怀疑这将是 Liferay 前端模板开发的一个更好的实现,因此前端可以为 java 团队提供已经知道速度模板的 html.
I suspect it would be a better implementation on Liferay's frontend template development, so the frontender can serve to the java team html already velocity templating aware.
非常感谢.
推荐答案
可以直接使用velocityjs 在浏览器上使用 browserify 后.
You can directly use velocityjs on browser after using browserify on it.
安装
首先在你的 node_modules 中安装velocityjs
First install velocityjs in your node_modules
<代码>$>npm install velocityjs
现在从你的项目(上面提到的 node_modules 存在的地方)使用 browserify
Now from your project (where the node_modules mentioned above exists) use browserify
browserify -r velocityjs >速度.js
这将创建一个velocity.js 文件,您可以直接将其包含在您的网站中.如果您没有 browserify,请执行 npm install -g browserify
This will create a velocity.js file that you can include in your website directly. If you don't have browserify then do npm install -g browserify
用法
在你的网页js文件中首先需要velocityjs
In your webpage js file first require velocityjs
var velocityjs = require("velocityjs");
现在来获取模板化的 html
Now to get the templated html do
var renderingString = velocityjs.render(initialString,context)
请注意,velocity 并不关心您的初始字符串是否为 html,您需要确保
Note that velocity does not care if your initial string was html or not, you need to ensure that
这篇关于在 js 页面中使用速度模板引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!