use velocity template engine in js page

流过昼夜 提交于 2019-12-06 09:41:48

You can directly use velocityjs on browser after using browserify on it.

Installation

First install velocityjs in your node_modules

$> npm install velocityjs

Now from your project (where the node_modules mentioned above exists) use browserify

browserify -r velocityjs > velocity.js

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

Usage

In your webpage js file first require velocityjs

var velocityjs = require("velocityjs");

Now to get the templated html do

var renderedString = velocityjs.render(initialString,context)

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!