Template expression reference
load
load(string|array files, bool recursive = false, int depth = null)
The expression load
will load the data from a separate file into our file.
{
"items": [
"expr:load('items/first.json')",
"expr:load('items/second.json')"
]
}
It is also possible to load multiple files using an array
{
"navigation": "expr:load(['navigation/main.json', 'navigation/main-active-contact.json'], true, 3)"
}
In this /data/navigation/main.json
and /data/navigation/main-active-contact.json
are loaded. By default, they will not be merged, so a later file will overwrite an existing key. Use the optional recursive
and depth
parameter to change this behaviour.
lorem_ipsum
lorem_ipsum(
bool html = false,
int|array paragraphs = 1,
int|array sentences = [3, 8],
int|array words = [3, 10],
int|array chars = [2,12],
int punctuationChance = 33
)
The lorem_ipsum
function helps you to generate blind text, that will always change on a reload.
{
"title": "expr:lorem_ipsum(false, 1, 1, [3, 10], [2, 12], 0)",
"description": "expr:lorem_ipsum()",
"content": "expr:lorem_ipsum(true, 10, [7, 10], [5, 20])"
}
By default, you don't need any parameter, but with the first you can set if the output is html (true
) or just plain text (false
).
The next four parameters control the amount of text, it expects a single int or a tuple array with two int, defining the max and min amount.
paragraphs: The number of paragraphs. Each paragraph is separated with break (newline in plaintext and <p>
in html).
sentences: The number of sentences in a paragraph.
words: The number of words in a sentence.
chars: The number of chars in a word.
The last option is the change of punctuation. That means, how often a comma will appear in a sentence. If the punctuation is 0
there will also be no .
in the end, this is useful for titles without a dot.
ref
ref(string file, string property)
Use ref
to load a specific value from another file. This approach helps us to keep your data at single point. Changes at this point will also affect the other files.
For example, you have a file /data/page/homepage.json
with following content:
{
"resource": {
"id": 1,
"title": "Home"
}
}
And in the file /data/navigation/main.json
you want to use the title from the homepage you use ref
.
{
"id": 2,
"nodes": [
{
"id": 5,
"name": "page",
"children": [],
"subject": {
"title": "expr:ref('page/homepage.json', 'resource.title')"
}
}
]
}
The second argument of ref
is mandatory, you can also pass a path to like resource.block.0.title
url
url(string url)
The url
is mandatory for every url you define in your data. Because in the dev environment we need add a prefix to every link.
{
"resource": {
"id": 1,
"title": "Home",
"url": "expr:url('page/homepage')"
}
}