MallaDocs

Référence des expressions

Opérateurs, variables de portée, fonctions fn intégrées et méthodes disponibles dans les expressions.

Guide utilisateur

Les expressions sont un sous-ensemble sûr de JavaScript. Cette page liste tout ce qu'elles peuvent utiliser. L'autocomplétion de l'éditeur est construite à partir des mêmes définitions : cette liste est donc toujours complète.

Syntaxe

js
// Arithmetic       + - * / % **
// Comparison       == != === !== < > <= >=
// Logic            && || ! ?? and  cond ? a : b
// Access           a.b  a[b]  a?.b
// Literals         'text'  `Hi ${user.name}`  [1, ...list]  { a: 1, ...obj }
// Lambdas          items.filter(x => x.price > 10)   (as call arguments only)

Portée

NomContientDisponible
varsles variables de page et de sitepartout
queries{ data, loading, error, updatedAt } pour chaque requêtepages
item, index, parentla ligne courante, sa position, la ligne englobantelistes de collection, pages modèles
pagepath, params, querypages
sitename, localepartout
userle visiteur, { isLoggedIn: false } quand il n'est pas connectépartout
steps, input, event, errorles résultats des étapes, l'entrée du workflow, l'événement déclencheur, une erreur interceptéeworkflows
rowla ligne en cours de lecture ou d'écriturerègles de ligne
fnles fonctions intégrées ci-dessous et vos formulespartout

Fonctions

Appelez les fonctions intégrées sous la forme fn.name(…). Les arguments marqués ? sont facultatifs. Les arguments de clé acceptent un chemin de champ ('author.name') ou une lambda.

Mise en forme

FonctionRenvoieDescription
fn.formatNumber(value, decimals?, locale?)stringLocale-formatted number with grouping. decimals is a fixed number of decimals or Intl.NumberFormat options ({ notation: "compact" }, { style: "percent" }). Empty string for null/undefined.
fn.formatNumber(1234.5, 2, 'en-US') // '1,234.50'
fn.formatCurrency(value, currency?, locale?, decimals?)stringLocale-formatted money amount (currency: ISO 4217 code, default USD).
fn.formatCurrency(item.price, 'EUR', 'de-DE') // '12,50 €'
fn.formatDate(date, format?, locale?, timeZone?)stringLocale-formatted date. Formats: short, medium (default), long, full, datetime, time, iso, isoDateTime, or Intl.DateTimeFormat options. Time zone defaults to UTC.
fn.formatDate(item.publishedAt, 'long', 'en-GB') // '1 March 2026'

Dates

FonctionRenvoieDescription
fn.now()dateCurrent time as an ISO string.
fn.now()
fn.dateAdd(date, amount, unit)dateAdds an amount of a unit (year, quarter, month, week, day, hour, minute, second). UTC; month math clamps to the last day.
fn.dateAdd(fn.now(), 7, 'day')
fn.dateDiff(from, to, unit?)numberWhole units from from to to (default day; negative when to is earlier).
fn.dateDiff(item.publishedAt, fn.now(), 'day')
fn.startOf(date, unit)dateStart of the unit containing the date (UTC; weeks start on Monday).
fn.startOf(fn.now(), 'month')

Texte

FonctionRenvoieDescription
fn.truncate(text, length, suffix?)stringCuts to length characters (suffix included, default …) when longer.
fn.truncate(item.excerpt, 120)
fn.slugify(text)stringKebab-case ASCII slug (Café Ñandú → cafe-nandu).

Tableaux

FonctionRenvoieDescription
fn.length(value)numberItems in an array, characters in a string, keys in an object; 0 otherwise.
fn.sum(items, key?)numberSum of the numeric values (non-numbers skipped).
fn.sum(queries.cart.data, 'price')
fn.avg(items, key?)numberAverage of the numeric values; null when there are none.
fn.uniq(items, key?)arrayItems with duplicates removed (by deep value, or by key).
fn.groupBy(items, key)objectObject of arrays keyed by the key value.
fn.groupBy(queries.products.data, 'category')
fn.sortBy(items, key?, direction?)arraySorted copy (asc default or desc): numbers numerically, strings by code point, null last.
fn.sortBy(items, 'price', 'desc')
fn.range(start, end?, step?)arrayNumbers from start (inclusive) to end (exclusive); fn.range(3) → [0, 1, 2].

Maths

FonctionRenvoieDescription
fn.min(...values)anySmallest value: fn.min(1, 2), fn.min(items, "price").
fn.max(...values)anyLargest value: fn.max(1, 2), fn.max(items, "price").
fn.round(value, decimals?)numberRounds half away from zero to decimals places (default 0).

Objets

FonctionRenvoieDescription
fn.keys(object)arrayOwn keys.
fn.values(object)arrayOwn values.
fn.entries(object)array[key, value] pairs.

Logique

FonctionRenvoieDescription
fn.default(value, fallback)anyThe fallback when the value is null, undefined or "".
fn.default(item.subtitle, 'Untitled')
fn.toNumber(value, fallback?)numberNumber from a number or numeric string; the fallback (default null) otherwise.

JSON

FonctionRenvoieDescription
fn.jsonStringify(value, indent?)stringJSON text (forbidden keys dropped; oversized values are errors).
fn.jsonParse(text, fallback?)anyParses JSON; the fallback (default null) when invalid. __proto__/constructor keys are dropped.

Méthodes

Les valeurs disposent aussi des méthodes JavaScript habituelles. Les méthodes ne modifient jamais l'original : sort et reverse renvoient des copies.

Méthodes de texte

MéthodeRenvoieDescription
.lengthnumberNumber of UTF-16 code units.
.toUpperCase()stringUpper-case copy.
.toLowerCase()stringLower-case copy.
.trim()stringRemoves leading and trailing whitespace.
.trimStart()stringRemoves leading whitespace.
.trimEnd()stringRemoves trailing whitespace.
.startsWith(search, position?)booleanTrue when the string starts with search.
.endsWith(search, length?)booleanTrue when the string ends with search.
.includes(search)booleanTrue when search occurs in the string.
.indexOf(search, from?)numberFirst index of search, or -1.
.lastIndexOf(search)numberLast index of search, or -1.
.slice(start?, end?)stringPart of the string (negative indexes count from the end).
.substring(start, end?)stringPart of the string between two indexes.
.split(separator, limit?)arraySplits on a literal separator.
.replace(search, replacement)stringReplaces the first literal occurrence.
.replaceAll(search, replacement)stringReplaces every literal occurrence.
.padStart(length, fill?)stringPads the start to length.
.padEnd(length, fill?)stringPads the end to length.
.repeat(count)stringThe string repeated count times.
.charAt(index)stringCharacter at an index.
.at(index)stringCharacter at an index (negative counts from the end).
.concat(...parts)stringAppends the parts.
.localeCompare(other, locale?)numberLocale-aware comparison (-1, 0, 1).
.toString()stringThe string itself.

Méthodes de tableau

MéthodeRenvoieDescription
.lengthnumberNumber of items.
.map(callback)arrayNew array with the callback result for each item: (item, index) => ….
.filter(callback)arrayItems for which the callback is truthy.
.find(callback)anyFirst item for which the callback is truthy.
.findIndex(callback)numberIndex of the first match, or -1.
.findLast(callback)anyLast item for which the callback is truthy.
.findLastIndex(callback)numberIndex of the last match, or -1.
.some(callback)booleanTrue when the callback is truthy for any item.
.every(callback)booleanTrue when the callback is truthy for every item.
.reduce(callback, initial?)anyFolds the items into one value: (acc, item, index) => ….
.flatMap(callback)arrayMaps, then flattens one level.
.includes(value)booleanTrue when the array contains the value (===).
.indexOf(value)numberFirst index of the value, or -1.
.lastIndexOf(value)numberLast index of the value, or -1.
.join(separator?)stringJoins the items into a string (default ,).
.slice(start?, end?)arrayPart of the array (negative indexes count from the end).
.concat(...values)arrayNew array with the values appended (arrays flattened one level).
.at(index)anyItem at an index (negative counts from the end).
.flat(depth?)arrayFlattens nested arrays (default depth 1, max 10).
.reverse()arrayReversed copy (the original never changes).
.sort(compare?)arraySorted copy (the original never changes). Without a comparator, sorts as strings like JS.

Méthodes de nombre

MéthodeRenvoieDescription
.toFixed(digits?)stringFixed-point notation (0–100 digits).
.toPrecision(precision)stringSignificant-digit notation (1–100).
.toString(radix?)stringText form, optionally in base 2–36.
.toLocaleString(locale?)stringLocale-formatted number (default: site locale).
.toString()string"true" or "false".