Render Context
The render context is one of the most important things to understand when creating a Pageous project. The render context is the data structure that gets passed to Mustache to dynamically render templates, layouts and other parts of a Pageous project.
Here is what the render context looks like:
{
"params": {
"query": { // query parameters on the request like ?foo=bar
"name": "value"
},
"body": {
// Body of the request
},
"path": { // path parameters captured from the URL like: /users/{id}
"name": "value"
}
"all": { // this is a combination of all of the above maps into one
"name": "value"
},
"env": { // Environment variables
"name": "value"
}
"cookies": { // Cookies
"name": "value"
}
},
"response": {
// Response data from request
},
"metadata": {
// Metadata from page
}
"multi": {
"request_reference_1": {
// Body of request 1
},
"request_reference_2": {
// Body of request 2
}
}
}
A map will never be empty, instead it will be null.
Most of this should be self explainatory but there are some caveats worth going over:
params.all: This is a combination of params.query
, params.body
and params.path
.
If the same parameter is defined in two or more of these places only one will show in in the all
map.
params.env: These are the environment variables passed from the environment to your application when it is launched.
response: This is the response of a request or mutation. If there are multiple requests for a page then this will be the response data from the request that is listed first when viewing the details of a page.
multi: This is a map of request references to responses for all the requests for the page. The request references can be found by viewing the details of a request.
Aliases
Some of the keys in the render context can be accessed through aliases allowing for shorthand in Mustache.
Key | Aliases |
---|---|
params | p, req |
response | res, r |
metadata | meta, m |
multi |