Skip to content
/ mplate Public

Render template from command line. Supports multiple engines and is pipeable with your favorites tools!

License

Notifications You must be signed in to change notification settings

m0xx/mplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mplate

Render template from command line. Supports multiple engines and is pipeable with your favorite tools!

Supported template engine

Installation

npm install -g mplate

Usage

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

Render template to file

./welcome.ejs

Welcome <%= username %>!
mplate --context "{\"username\": \"admin\"}" -f welcome.ejs -o out.txt

Render template from stream

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!

Use environment variables

echo "User home:<%= USER_HOME %>" | mplate -f - --use-env
User home: ~/user/home

Load context from file

./context.yaml

user:
    name: admin
echo "Welcome <%= user.name %>!" | mplate -f - --context-file context.yaml --context-format yaml
Welcome admin!

Render with a different engine (handlebars)

echo "Welcome {{ username }}!" | mplate -f - --context "{\"username\": \"admin\"}" --engine handlebars
Welcome admin!

About

Render template from command line. Supports multiple engines and is pipeable with your favorites tools!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •