Template variables and rendering context
Amagaki’s document route provider will render all documents configured with
URLs. Binding a URL to a document means “render me as a page”. Documents without
URLs are not built as pages.
When Amagaki renders a document, it selects a template (either the pod’s default
template or a template bound to a collection), and renders it with the following
context object.
Template variables
Here is the top-level rendering context available when templates are rendered:
doc
A reference to the current document being rendered. All properties of the
document are available. Some commonly used ones are:
doc.body
– The document's body (i.e. for Markdown or HTML documents)doc.collection
– A reference to the document’s collectiondoc.fields
– The document's front matterdoc.locale
– A reference to the document's locale
pod
A reference to the pod. All pod functions are available from the pod
object,
which can be invoked from your templates. Some commonly used ones are:
pod.collection(...)
– Returns a collection objectpod.collections(...)
– Returns a list of collectionspod.doc(...)
– Returns a document objectpod.docs(...)
– Returns a list of documentspod.env
– Returns the current rendering environmentpod.readYaml(...)
– Returns content from a YAML filepod.staticFile(...)
– Returns a static file object
process
The NodeJS.Process
object.
req
The Express request object. Warning! This object is only available when using
the server. The object is undefined
when generating a static site.
route
A reference to the route binding the URL to the document. Some commonly used
properties of the route are:
route.fields
– Any data fields added to the route (i.e. by a route provider)route.params
– Any params used when matching the request to the routeroute.url
– A reference to the document's Url object