Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hmpo-govuk-template

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hmpo-govuk-template

Compile govuk mustache template into a more usable format and provide middleware for use in apps

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
Maintainers
4
Weekly downloads
 
Created
Source

hmpo-govuk-template

Compiles govuk mustache template into a more usable format and provide middleware for use in apps.

Existing govuk mustache template has simple mustache placeholders for content sections, which necessitates a two step compile process where sections are compiled individually and then again into the parent template.

Compiling the template to replace these placeholders with variables allows for templates to implement the govuk template as a parent partial.

Example

{{< govuk-template}}

    {{$main}}
        <h1>Page Content</h1>
    {{/main}}

{{/ govuk-template}}

Installation

npm install [--save] hmpo-govuk-template

Usage

The compilation of the template is performed automatically as an npm postinstall hook.

When used as part of an express app, a setup method is provided which will add a static-middleware (using serve-static) to serve the template assets without needing to copy them to any other location.

It will also add the template as a mustache partial with a name of "govuk-template".

To configure express middleware

require('hmpo-govuk-template').setup(app[, { ... options ...}]);

To only load the partial location but not serve the assets use the template function. The govukAssetPath local will need to set to the absolute public asset location.

app.use(function (req, res, next) {
    res.locals = res.locals || {};
    res.locals.govukAssetPath = '/absolute/asset/path'
});
app.use(require('hmpo-govuk-template').template);

To use the mustache partial

{{< govuk-template}}
    {{$pageTitle}}An example page{{/pageTitle}}
    {{$main}}
        <h1>Page Content</h1>
    {{/main}}
{{/ govuk-template}}

Options

A number of options can be passed with the app into the setup method:

  • path - Sets the base path for the location of static assets - Default: /govuk-assets

Other options are passed onto the serve-static configuration, and more details can be found in the serve-static documentation

Example

There is an example implmentation in '/example'. To run:

cd example
npm install
npm start

FAQs

Package last updated on 10 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc