Config Functions

Maizzle is fully configured in JavaScript, so you can programmatically set config options or process and make data available to your Templates.

When using a function, you need to make sure that:

  1. it returns something
  2. you invoke it
config.js
const imaginaryLib = require('imaginary-lib')

const foo = function() {
  return 'manchu'
}

module.exports = {
  foo: foo(), // invoke function defined above
  bar: function() {
    // do stuff and return
    return 'baz'
  }(), // invoke function
  wha: () => imaginaryLib.render('implicit return 👌')
}

You would access those variables under the page object:

src/templates/example.html
<extends src="src/layouts/main.html">
  <block name="template">
    <p>{{ page.foo }}</p>
    <p>{{ page.bar }}</p>
    <p>{{ page.wha }}</p>
  </block>
</extends>

Result:

src/templates/example.html
<p>manchu</p>
<p>baz</p>
<p>implicit return 👌</p>
Copyright © 2022 Maizzle SRL Brand policy
Edit this page on GitHub