fileTransform
and can be a String, Object or Array[String / Object].
Variables are included on a page using double curly braces (e.g. {{variableName}}
)
Below is an example showing how to set up and use variables in your pipeline: // Summarised Pipeline Config
const template = require('quantum-template')
const templateOptions = {
// Define the variables to use:
variables: {
exampleString: 'my string',
exampleList: ['a', 'b', 'c'],
exampleObjectList: [
{ head: 'Something', body: 'Content 1' },
{ body: 'Content 2' }
],
exampleObject: {
name: 'Dave',
age: 25
}
}
}
module.exports = {
pipeline: [
// Add to your pipeline
template.fileTransform(templateOptions)
]
}
# Use the `exampleString` variable as the title
@h1: {{exampleString}}
# Object properties are referenced with a dot:
@h2: {{exampleObject.name}}, {{exampleObject.age}}
# Loop through the items in an array:
@for item in exampleList
@bold[{{item}}]
@br
# Loop through an array of objects:
@for item in exampleObjectList
@if item.head
@h3: {{item.head}}
@p: {{item.body}}
# Loop through the keys/values of an object
@for key value in exampleObject
@p: @b[key:] {{key}}, @bold[value:] {{value}}
@ifnot nonExistentVariable
@p: Display This
@ifnot exampleString
@p: This won't display because exampleString exists
Content 1
Content 2
key: name, value: Dave
key: age, value: 25
Display This
@template
at the root of a page. This is most sensibly done using @inline
.
The fileTransform
processes the @template
, finds the @contentEntity
and moves everything outside the template into the content entity. @template
@contentEntityName templateContent
@content
@header
@icon [/resources/logo.svg] [/]
@title QuantumJS
@sidebarPage
@sidebar
@navigationMenu
@section Introduction
@page /: Home
@page /page-1: Page 1
@content
@templateContent
@inline /templates/template.um
@contentSection
@topic Home
Some information on the home page
@inline /templates/template.um
@contentSection
@topic Page 1
Some information on page 1
require('quantum-template')
.
For information about different versions, see the Changelog @for
, @if
provided by this module. template.fileTransform({
variables: {
myVar: 'my variable'
}
})
@h3: Heading
@p: {{myVar}}
my variable
fileTransform
that processes the @template
entities. const wrapper = require('quantum-template').wrapper
// Example use in pipeline
const pipeline = [
(file) => {
return file.clone({
content: wrapper(file.content)
})
}
]
...
// Variables passed into fileTransform
{
exampleList: ['a', 'b', 'c'],
exampleObjectList: [
{ head: 'Something', body: 'Content 1' },
{ body: 'Content 2' }
],
exampleObject: {
name: 'Dave',
age: 25
}
}
...
@h3: Loop through list
@for item in exampleList
@bold[{{item}}]
@br
@h3: Loop through list of objects
@for item in exampleObjectList
@if item.head
@h3: {{item.head}}
@p: {{item.body}}
@h3: Loop through object keys
@for key value in exampleObject
@p: @b[key:] {{key}}, @bold[value:] {{value}}
Content 1
Content 2
key: name, value: Dave
key: age, value: 25
...
// Variables passed into fileTransform
{
exampleString: 'my string'
}
...
@if exampleString
@h3: exampleString is declared
{{exampleString}}
@if undeclaredVariable
@h3: Variable not declared, this will not show
@if
, can be used as an 'else' statement for @if
blocks. It displays content if a the value of a variable is falsey. ...
// Variables passed into fileTransform
{
exampleString: 'my string'
}
...
@ifnot exampleString
@h3: exampleString is declared, this will not show
{{exampleString}}
@ifnot undeclaredVariable
@h3: Variable not declared, this will show
@contentEntityName
@content
@template
@contentEntityName someEntity
@someEntity
# Content would be placed here