npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@transomjs/transom-ejs-template

v3.0.0

Published

A TransomJS module to provide EJS templating for email and html

Downloads

7

Readme

transom-ejs-template

Add simple EJS templating functions to your server-side Transomjs code.

Build Status Coverage Status

Installation

$ npm install --save @transomjs/transom-ejs-template

Usage

Transom-ejs-template is a module that provides a really simple way to send HTML (or text) formatted emails or render simple web pages. Using all the features of EJS, you can insert data into your templates or include other ejs templates using a relative path.

After transom.initialize, an object is stored in the registry with 'transomTemplate' as the key. Each of the following methods will return a completely rendered template with all includes resolved and interpolated data.

    server.get('/about', function (req, res, next) {
        // Fetch the configured Template module from the Registry.
        const template = server.registry.get('transomTemplate');

        // Some simple data for insertion into the template.
        const data = {
            title: "My Dawg Walker App",
            date: new Date(),
            year: new Date().getFullYear()
        };
        const content = template.renderHtmlTemplate('about', data);

        // Tell the browser what type of content we're sending.
        res.setHeader('content-type', 'text/html');
        res.end(content);
        next(false);
    });

Render HTML templates

renderHtmlTemplate(templateName, data, htmlOptions)

  • templateName is the filename as found in the templatePath, without the ".ejs" extension.
  • data is a JavaScript object containing anything that might be used within the template or it's nested child templates. Several attributes are added to data each time, the include:
    • environment is set to the process.env.NODE_ENV or 'DEVELOPMENT'
    • [deprecated] envMessage is set empty when the environment equals 'PRODUCTION', otherwise it contains: This page is in ${data.environment}.
    • [deprecated] hostname is pulled from the request. If not found, it contains '/';
    • [deprecated] pageTitle is set to the templateName if it's not provided by the caller;
  • htmlOptions.templatePath allows overriding the default path and loading a template from somewhere else;

Render Email templates

renderEmailTemplate(templateName, data, emailOptions)

  • templateName is the filename as found in the templatePath, without the ".ejs" extension.
  • data is a JavaScript object containing anything that might be used within the template or it's nested child templates. Several attributes are added to data each time, they include:
    • environment is set to the process.env.NODE_ENV or 'DEVELOPMENT'
    • templateName is set to the filename of the current template
  • emailOptions.templatePath allows overriding the default path and loading a template from somewhere else.

Testing

When running tests and looking for templates, set the process.env.NODE_ENV to TESTING to locate templates in the ../test folder.

Updating from 1.x.x

EJS templating for includes has changed between transom-ejs 1.x.x and 2.0.0.

In the version 1 release, we were able to include EJS templates with the following syntax.

<% include user/show %>

The correct syntax should be:

<%- include('user/show') %>

Need Support?

TransomJS is developed and maintained by BinaryOps Software Inc. in Canada.