0.1.7 • Published 10 years ago

hapi-locals v0.1.7

Weekly downloads
5
License
MIT
Repository
github
Last release
10 years ago

Hapi Locals

A Hapi plugin to add local variables and functions to all templates rendered.

Goal:

Add server method "locals" to add global variables and functions for all templates. Just like app.locals in expressjs.

How to use

// register plugin
plugins = [];

plugins.push({
  register: require("hapi-locals")
});

// or, with hoek merge options
plugins.push({
  register: require('hapi-locals'),
  options: {
    isMergeArrays: false
  }
});

server.register(plugins, function(err) {
  if (err) {
    throw err;
  }
});

// set local variable or function
server.methods.locals("siteTitle", "My SiteTitle");

server.methods.locals("cacheVer", "1922");

server.methods.locals("sayHi", function(name) {
  return "Hello " + name;
});

Using in jade template

title #{siteTitle}

link(rel='stylesheet', href='/public/css/main.css?#{cacheVer}')

p!= sayHi("Tony")

Plugin Options

hapi-locals use hoek.merge to merge the context, you can set the merge parameters in options

isNullOverride

default to true

isMergeArrays

default to true

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago