Coder Social home page Coder Social logo

anvil.ejs's Introduction

Anvil EJS Plugin

This plugin allows you to build static html files from ejs templates.

Anvil.ejs requires anvil.js version 0.8.* or greater and EJS 0.8.3 or greater.

Installation

anvil install anvil.ejs

Usage

If this plugin is installed and enabled, by default all .html and .ejs files will run ejs to compile from the data in the build.json file.

Passing data into the templates

All of the ejs templates will have the data from the anvil build.json file passed into them. For example:

{
	"anvil.ejs": {
		"data": {
			"hello": "Hello World!"
		}
	}
}

when paired with a template like this:

<div class="my-div"><%= hello %></div>

would render this after an anvil build:

<div class="my-div">Hello World</div>

Rendering Partials

The only non-standard EJS function that this plugin currently extends is for rendering partials. The markup is based off of the Express implementation of EJS templates. The first argument should be the path to the partial template. There is no need to include the file extension because Anvil.EJS will loop over the supported formats and find the template for you. The second argument can be any parameters you want to pass into the template. The partials will also inherit any data from the build.js file.

With a partials/header.html file like this:

<h1><%= title %></h1>

and an index.html file like this:

<%- partial("partials/header", { title: "My Awesome Header" }) %>
<h2>This is the index.html page!</h2>

The index.html page would be built to look like this:

<h1>My Awesome Header</h1>
<h2>This is the index.html page!</h2>

Supporting other filetypes

By default, anvil.ejs works for .html, .ejs files. You can also pass in an array of the file types you would like to run through ejs in you project like this:

{
	"anvil.ejs": {
		"formats": ["foo", "bar", "html"]
	}
}

Support

This plugin was created by Tyson Cadenhead. Please feel free to ask me a question or submit a pull request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.