在js页面中使用速度模板引擎 [英] use velocity template engine in js page

查看:116
本文介绍了在js页面中使用速度模板引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一些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?

您将如何作为工作流?

我怀疑这将是对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 > velocity.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 renderedString = velocityjs.render(initialString,context)

请注意,速度并不关心您的初始字符串是否为html,您需要确保

Note that velocity does not care if your initial string was html or not, you need to ensure that

这篇关于在js页面中使用速度模板引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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