Render template from command line. Supports multiple engines and is pipeable with your favorite tools!
- ejs default
- es6
- Handlebars
npm install -g mplate
Usage: mplate [options]
Template utilities
Options:
-V, --version output the version number
-f --file <file> Template input file. '-' to read from stdin
-o --output <output> Output file
-e --engine <engine> Template engine (default: "ejs")
-c --context <context> Template context for interpolation in JSON (default: "{}")
--context-file <contextFile> Load context from file
--context-format <contextFormat> Context format (default: "json")
--use-env Merge environment variable in context
./welcome.ejs
Welcome <%= username %>!
mplate --context "{\"username\": \"admin\"}" -f welcome.ejs -o out.txt
echo "Welcome <%= username %>!" | mplate -f - --context "{\"username\": \"admin\"}"
Welcome admin!
From file server:
curl -s https://example.com/template/location.ejs | mplate -f - --context "{\"username\": \"admin\"}"
Welcome admin!
echo "User home:<%= USER_HOME %>" | mplate -f - --use-env
User home: ~/user/home
./context.yaml
user:
name: admin
echo "Welcome <%= user.name %>!" | mplate -f - --context-file context.yaml --context-format yaml
Welcome admin!
echo "Welcome {{ username }}!" | mplate -f - --context "{\"username\": \"admin\"}" --engine handlebars
Welcome admin!