{
  "version": "https://jsonfeed.org/version/1.1",
  "title": "Cecil - Fonctions et filtres",
  "home_page_url": "https://cecil.app/fr/documentation/templates/reference/",
  "feed_url": "https://cecil.app/fr/documentation/templates/reference/feed.json",
  "description": "Référence des fonctions, tris et filtres Twig fournis par Cecil.",
  "icon": "https://cecil.app/favicon.7ff4b89eec6dad139a7d2d6561543285.png",
  "favicon": "https://cecil.app/thumbnails/64x/favicon.7ff4b89eec6dad139a7d2d6561543285.png",
  "language": "fr",
  "items": [
    {
      "id": "https://cecil.app/fr/documentation/templates/reference/fonctions/",
      "url": "https://cecil.app/fr/documentation/templates/reference/fonctions/",
      "title": "Fonctions",
      "summary": "url, html, readtime, hash, cache_key, getenv, dump, etc.",
      "date_published": "2026-05-26T00:00:00+00:00",
      "date_modified": "2026-10-05T00:00:00+00:00","content_text": "Fonctions\n\nFonctions peut être appelée pour générer du contenu. Les fonctions sont appelées par leur nom suivi de parenthèses (()) et peuvent avoir des arguments.\n\nurl\nCrée une URL valide pour une page, une entrée de menu, un actif, un ID de page ou un chemin.\n{{ url(value, {options}) }}\n\n\n\nOptions\nDescriptif\nTapez\nPar défaut\n\n\n\n\ncanonique\nPréfixez l'URL avec baseurl ou utilisez canonical.url s'il existe.\nbooléen\nfalse\n\n\nformats\nDéfinit la page format de sortie (par exemple : json).\nchaîne\nhtml\n\n\nlangue\nDéfinit la page langue (ex. : fr).\nchaîne\nnul\n\n\n\nExemples :\n{# page #}\n{{ url(page) }}\n{{ url(page, {canonical: true}) }}\n{{ url(page, {format: json}) }}\n{{ url(page, {language: fr}) }}\n{# menu entry #}\n{{ url(site.menus.main.about) }}\n{# asset #}\n{{ url(asset('styles.css')) }}\n{# page ID #}\n{{ url('page-id') }}\n{# path #}\n{{ url('about-me\/') }}\n{{ url('tags\/' ~ tag) }}\nPour plus de commodité, la fonction url est également disponible sous forme de filtre :\n{# page #}\n{{ page|url }}\n{{ page|url({canonical: true, format: json, language: fr}) }}\n{# asset #}\n{{ asset('styles.css')|url }}\nLorsque la valeur est une chaîne, url() la « slugifie » pour trouver un ID de page correspondant (ex. : url('tags\/My Tag') retourne l’URL de la page tags\/my-tag). Si aucune page ne correspond, la chaîne est conservée comme chemin, avec les caractères invalides (ex. : espaces) encodés.\nhtml\nCrée un élément HTML à partir d'un actif (ou d'un tableau d'actifs avec des attributs personnalisés).\n{{ html(asset, {attributes}, {options}) }}\n{# dedicated functions for each common type of asset #}\n{{ css(asset) }}\n{{ js(asset) }}\n{{ image(asset) }}\n{{ audio(asset) }}\n{{ video(asset) }}\n\n\n\nOptions\nDescriptif\nTapez\n\n\n\n\nattributs\nAjoute le couple name=\"value\" à l'élément HTML.\ntableau\n\n\noptions\n{preload: boolean} : préchargements.Pour les images :{formats: array} : ajoute des formats alternatifs.{responsive: bool|string} : ajoute des images réactives (basées sur width ou des pixels density).{placeholder: string} : remplit l'arrière-plan de l'image avant son chargement (color ou lqip).\ntableau\n\n\n\nDepuis la version 8.42.0, la fonction html remplace le filtre html obsolète.\nVous pouvez définir un comportement global par défaut des options d'images (formats, responsive et placeholder) via la configuration des layouts.\nLorsque layouts.images.dark_suffix est configuré (par exemple .dark), Cecil recherche automatiquement une variante sombre de chaque image (par exemple photo.dark.jpg aux côtés de photo.jpg) et génère un élément &lt;picture&gt; avec un &lt;source media=\"(prefers-color-scheme: dark)\"&gt;.\nDe la même manière, lorsque layouts.images.mobile_suffix est configuré (par exemple .mobile), Cecil recherche une variante mobile de chaque image (par exemple photo.mobile.jpg) et ajoute un &lt;source&gt; avec la media query layouts.images.mobile_media_query. Si une variante sombre de l’image mobile existe (par exemple photo.mobile.dark.jpg), elle est utilisée sur mobile en mode sombre.\nExemples :\n{# CSS with an attribute #}\n{{ html(asset('print.css'), {media: 'print'}) }}\n{# CSS with an attribute and an option #}\n{{ html(asset('styles.css'), {title: 'Main theme'}, {preload: true}) }}\n{# Array of assets with media query #}\n{{ html([\n  {asset: asset('css\/style.css')},\n  {asset: asset('css\/style-dark.css'), attributes: {media: '(prefers-color-scheme: dark)'}}\n]) }}\n{# JavaScript #}\n{{ html(asset('script.js')) }}\n{# image without specific attributes nor options #}\n{{ html(asset('image.png')) }}\n{# image with specific attributes, responsive images and alternative formats #}\n{{ html(asset('image.jpg'), {alt: 'Description', loading: 'lazy'}, {responsive: true, formats: ['avif', 'webp']}) }}\n{# image with responsive pixels density images #}\n{{ html(asset('image.jpg'), options={responsive: 'density'}, attributes={width: 256}) }}\n{# image with a Low-Quality Image Placeholder #}\n{{ html(asset('image.jpg'), {alt: 'Description', loading: 'lazy'}, {placeholder: 'lqip'}) }}\n{# Audio #}\n{{ html(asset('audio.mp3')) }}\n{# Video #}\n{{ html(asset('video.mp4')) }}\nPour plus de commodité, la fonction html reste disponible en tant que filtre (mais est considérée comme obsolète) :\n{{ asset|html({attributes}, {options}) }}\nreadtime\nDétermine le temps de lecture d'un texte, en minutes.\n{{ readtime(value) }}\nExemple:\n{{ readtime(page.content) }} min\nhash\nCalcule le hachage d'un objet, d'un tableau ou d'une chaîne avec un algorithme donné.\n{{ hash(value, algorithm) }}\nalgorithm peut être n'importe quel algorithme pris en charge par la fonction hash() de PHP (par exemple : md5, sha256, etc.). La valeur par défaut est xxh128.\nExemple:\n{{ hash('my string', 'sha256') }}\ncache_key\nCalcule une clé de cache pour fragments cache en fonction d'un nom et d'une valeur facultative.\n{% cache cache_key(name, value) %}\n  {# cacheable content #}\n{% endcache %}\nLa fonction ajoute un hachage de la valeur (peut être une chaîne, un tableau ou un objet) au nom (ainsi que la langue actuelle et l'ID de build pour être sûr que la clé de cache générée est unique), donc si la valeur est modifiée, la clé de cache est également modifiée et le cache est automatiquement vidé.\ngetenv\nObtient la valeur d'une variable d'environnement à partir de sa clé.\n{{ getenv(var) }}\nExemple:\n{{ getenv('VAR') }}\ndump\nLa fonction dump affiche les informations sur une variable de modèle. Ceci est surtout utile pour déboguer un modèle qui ne se comporte pas comme prévu en introspectant ses variables :\n{{ dump(user) }}\nLe debug mode doit être activé.\nd\nLa fonction d() est la version HTML de dump() et utilise le Symfony VarDumper Component en arrière-plan.\n{{ d(variable, {theme: light}) }}\n\nSi variable n'est pas fourni, la fonction renvoie le contexte Twig actuel\nLes thèmes disponibles sont « clair » (par défaut) et « sombre »\n\nLe debug mode doit être activé.",
      "content_html": "<h1>Fonctions</h1>\n<blockquote>\n<p><a href=\"https://twig.symfony.com/doc/functions/index.html\" target=\"_blank\" rel=\"noopener noreferrer\">Fonctions</a> peut être appelée pour générer du contenu. Les fonctions sont appelées par leur nom suivi de parenthèses (<code translate=\"no\">()</code>) et peuvent avoir des arguments.</p>\n</blockquote>\n<h2 id=\"url\">url</h2>\n<p>Crée une URL valide pour une page, une entrée de menu, un actif, un ID de page ou un chemin.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ url(value, {options}) }}</span></code></pre>\n<table>\n<thead>\n<tr>\n<th>Options</th>\n<th>Descriptif</th>\n<th>Tapez</th>\n<th>Par défaut</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>canonique</td>\n<td>Préfixez l'URL avec <a href=\"../../configuration/22-site.fr.md#baseurl\"><code translate=\"no\">baseurl</code></a> ou utilisez <a href=\"../../configuration/22-site.fr.md#options-metatags\"><code translate=\"no\">canonical.url</code></a> s'il existe.</td>\n<td>booléen</td>\n<td><code translate=\"no\">false</code></td>\n</tr>\n<tr>\n<td>formats</td>\n<td>Définit la page <a href=\"../../configuration/29-output.fr.md#output-formats\">format de sortie</a> (par exemple : <code translate=\"no\">json</code>).</td>\n<td>chaîne</td>\n<td><code translate=\"no\">html</code></td>\n</tr>\n<tr>\n<td>langue</td>\n<td>Définit la page <a href=\"../../configuration/23-languages.fr.md#language\">langue</a> (ex. : <code translate=\"no\">fr</code>).</td>\n<td>chaîne</td>\n<td>nul</td>\n</tr>\n</tbody>\n</table>\n<p><em>Exemples :</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-comment\">{# page #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ url(page) }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ url(page, {canonical: true}) }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ url(page, {format: json}) }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ url(page, {language: fr}) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# menu entry #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ url(site.menus.main.about) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# asset #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ url(asset('styles.css')) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# page ID #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ url('page-id') }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# path #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ url('about-me/') }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ url('tags/' ~ tag) }}</span></code></pre>\n<aside class=\"note note-info\"><p>Pour plus de commodité, la fonction <code translate=\"no\">url</code> est également disponible sous forme de filtre :</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-comment\">{# page #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ page|url }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ page|url({canonical: true, format: json, language: fr}) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# asset #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ asset('styles.css')|url }}</span></code></pre></aside>\n<aside class=\"note note-tip\"><p>Lorsque la valeur est une chaîne, <code translate=\"no\">url()</code> la « slugifie » pour trouver un ID de page correspondant (ex. : <code translate=\"no\">url('tags/My Tag')</code> retourne l’URL de la page <code translate=\"no\">tags/my-tag</code>). Si aucune page ne correspond, la chaîne est conservée comme chemin, avec les caractères invalides (ex. : espaces) encodés.</p></aside>\n<h2 id=\"html\">html</h2>\n<p>Crée un élément HTML à partir d'un actif (ou d'un tableau d'actifs avec des attributs personnalisés).</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ html(asset, {attributes}, {options}) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# dedicated functions for each common type of asset #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ css(asset) }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ js(asset) }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ image(asset) }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ audio(asset) }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ video(asset) }}</span></code></pre>\n<table>\n<thead>\n<tr>\n<th>Options</th>\n<th>Descriptif</th>\n<th>Tapez</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>attributs</td>\n<td>Ajoute le couple <code translate=\"no\">name=\"value\"</code> à l'élément HTML.</td>\n<td>tableau</td>\n</tr>\n<tr>\n<td>options</td>\n<td><code translate=\"no\">{preload: boolean}</code> : préchargements.<br>Pour les images :<br><code translate=\"no\">{formats: array}</code> : ajoute des formats alternatifs.<br><code translate=\"no\">{responsive: bool|string}</code> : ajoute des images réactives (basées sur <code translate=\"no\">width</code> ou des pixels <code translate=\"no\">density</code>).<br><code translate=\"no\">{placeholder: string}</code> : remplit l'arrière-plan de l'image avant son chargement (<code translate=\"no\">color</code> ou <code translate=\"no\">lqip</code>).</td>\n<td>tableau</td>\n</tr>\n</tbody>\n</table>\n<aside class=\"note note-warning\"><p>Depuis la version <ins>8.42.0</ins>, la fonction <code translate=\"no\">html</code> remplace le filtre <code translate=\"no\">html</code> obsolète.</p></aside>\n<aside class=\"note note-tip\"><p>Vous pouvez définir un comportement global par défaut des options d'images (<code translate=\"no\">formats</code>, <code translate=\"no\">responsive</code> et <code translate=\"no\">placeholder</code>) via la <a href=\"../../configuration/28-layouts.fr.md#layouts-images\">configuration des layouts</a>.\nLorsque <a href=\"../../configuration/28-layouts.fr.md#layouts-images\"><code translate=\"no\">layouts.images.dark_suffix</code></a> est configuré (par exemple <code translate=\"no\">.dark</code>), Cecil recherche automatiquement une variante sombre de chaque image (par exemple <code translate=\"no\">photo.dark.jpg</code> aux côtés de <code translate=\"no\">photo.jpg</code>) et génère un élément <code translate=\"no\">&lt;picture&gt;</code> avec un <code translate=\"no\">&lt;source media=\"(prefers-color-scheme: dark)\"&gt;</code>.\nDe la même manière, lorsque <a href=\"../../configuration/28-layouts.fr.md#layouts-images\"><code translate=\"no\">layouts.images.mobile_suffix</code></a> est configuré (par exemple <code translate=\"no\">.mobile</code>), Cecil recherche une variante mobile de chaque image (par exemple <code translate=\"no\">photo.mobile.jpg</code>) et ajoute un <code translate=\"no\">&lt;source&gt;</code> avec la media query <a href=\"../../configuration/28-layouts.fr.md#layouts-images\"><code translate=\"no\">layouts.images.mobile_media_query</code></a>. Si une variante sombre de l’image mobile existe (par exemple <code translate=\"no\">photo.mobile.dark.jpg</code>), elle est utilisée sur mobile en mode sombre.</p></aside>\n<p><em>Exemples :</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-comment\">{# CSS with an attribute #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ html(asset('print.css'), {media: 'print'}) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# CSS with an attribute and an option #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ html(asset('styles.css'), {title: 'Main theme'}, {preload: true}) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# Array of assets with media query #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ html([\n  {asset: asset('css/style.css')},\n  {asset: asset('css/style-dark.css'), attributes: {media: '(prefers-color-scheme: dark)'}}</span><span class=\"xml\">\n]) }}\n</span><span class=\"hljs-comment\">{# JavaScript #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ html(asset('script.js')) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# image without specific attributes nor options #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ html(asset('image.png')) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# image with specific attributes, responsive images and alternative formats #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ html(asset('image.jpg'), {alt: 'Description', loading: 'lazy'}, {responsive: true, formats: ['avif', 'webp']}) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# image with responsive pixels density images #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ html(asset('image.jpg'), options={responsive: 'density'}, attributes={width: 256}) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# image with a Low-Quality Image Placeholder #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ html(asset('image.jpg'), {alt: 'Description', loading: 'lazy'}, {placeholder: 'lqip'}) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# Audio #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ html(asset('audio.mp3')) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# Video #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ html(asset('video.mp4')) }}</span></code></pre>\n<aside class=\"note note-info\"><p>Pour plus de commodité, la fonction <code translate=\"no\">html</code> reste disponible en tant que filtre (mais est considérée comme obsolète) :</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ asset|html({attributes}, {options}) }}</span></code></pre></aside>\n<h2 id=\"readtime\">readtime</h2>\n<p>Détermine le temps de lecture d'un texte, en minutes.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ readtime(value) }}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ readtime(page.content) }}</span><span class=\"xml\"> min</span></code></pre>\n<h2 id=\"hash\">hash</h2>\n<p>Calcule le hachage d'un objet, d'un tableau ou d'une chaîne avec un algorithme donné.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ hash(value, algorithm) }}</span></code></pre>\n<p><code translate=\"no\">algorithm</code> peut être n'importe quel algorithme pris en charge par la fonction <code translate=\"no\">hash()</code> de PHP (par exemple : <code translate=\"no\">md5</code>, <code translate=\"no\">sha256</code>, etc.). La valeur par défaut est <code translate=\"no\">xxh128</code>.</p>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ hash('my string', 'sha256') }}</span></code></pre>\n<h2 id=\"cache-key\">cache_key</h2>\n<p>Calcule une clé de cache pour <a href=\"../17-cache.fr.md#fragments-de-cache\"><em>fragments</em> cache</a> en fonction d'un nom et d'une valeur facultative.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\">cache</span> cache_key(name, value) %}</span><span class=\"xml\">\n  </span><span class=\"hljs-comment\">{# cacheable content #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\">endcache</span> %}</span></code></pre>\n<p>La fonction ajoute un hachage de la valeur (peut être une chaîne, un tableau ou un objet) au nom (ainsi que la langue actuelle et l'ID de build pour être sûr que la clé de cache générée est unique), donc si la valeur est modifiée, la clé de cache est également modifiée et le cache est automatiquement vidé.</p>\n<h2 id=\"getenv\">getenv</h2>\n<p>Obtient la valeur d'une variable d'environnement à partir de sa clé.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ getenv(var) }}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ getenv('VAR') }}</span></code></pre>\n<h2 id=\"dump\">dump</h2>\n<p>La fonction <code translate=\"no\">dump</code> affiche les informations sur une variable de modèle. Ceci est surtout utile pour déboguer un modèle qui ne se comporte pas comme prévu en introspectant ses variables :</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ <span class=\"hljs-name\">dump</span><span class=\"hljs-params\">(user)</span> }}</span></code></pre>\n<aside class=\"note note-important\"><p>Le <a href=\"../../configuration/22-site.fr.md#debug\"><em>debug mode</em></a> doit être activé.</p></aside>\n<h2 id=\"d\">d</h2>\n<p>La fonction <code translate=\"no\">d()</code> est la version HTML de <a href=\"#dump\"><code translate=\"no\">dump()</code></a> et utilise le <a href=\"https://symfony.com/doc/5.4/components/var_dumper.html\" target=\"_blank\" rel=\"noopener noreferrer\">Symfony VarDumper Component</a> en arrière-plan.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ d(variable, {theme: light}) }}</span></code></pre>\n<ul>\n<li>Si <em>variable</em> n'est pas fourni, la fonction renvoie le contexte Twig actuel</li>\n<li>Les thèmes disponibles sont « clair » (par défaut) et « sombre »</li>\n</ul>\n<aside class=\"note note-important\"><p>Le <a href=\"../../configuration/22-site.fr.md#debug\"><em>debug mode</em></a> doit être activé.</p></aside>",
      "language": "fr"
    },
    {
      "id": "https://cecil.app/fr/documentation/templates/reference/tris/",
      "url": "https://cecil.app/fr/documentation/templates/reference/tris/",
      "title": "Tris",
      "summary": "Triez des collections de pages, menus ou taxonomies.",
      "date_published": "2026-05-26T00:00:00+00:00",
      "date_modified": "2026-10-05T00:00:00+00:00","content_text": "Tris\nTri des collections (de pages, menus ou taxonomies).\nsort_by_title\nTrie une collection par titre (avec tri naturel).\n{{ collection|sort_by_title }}\nExemple:\n{{ site.pages|sort_by_title }}\nsort_by_date\nTrie une collection par date (la plus récente en premier).\n{{ collection|sort_by_date(variable='date', desc_title=false) }}\nExemple:\n{# sort by date #}\n{{ site.pages|sort_by_date }}\n{# sort by updated variable instead of date #}\n{{ site.pages|sort_by_date(variable='updated') }}\n{# sort items with the same date by desc title #}\n{{ site.pages|sort_by_date(desc_title=true) }}\n{# reverse sort #}\n{{ site.pages|sort_by_date|reverse }}\nsort_by_weight\nTrie une collection par poids (le plus léger en premier).\n{{ collection|sort_by_weight }}\nExemple:\n{{ site.menus.main|sort_by_weight }}\nsort\nPour les cas plus complexes, vous devez utiliser le sort natif de Twig.\nExemple:\n{% set files = site.static|sort((a, b) =&gt; a.date|date('U') &lt; b.date|date('U')) %}",
      "content_html": "<h1>Tris</h1>\n<p>Tri des collections (de pages, menus ou taxonomies).</p>\n<h2 id=\"sort-by-title\">sort_by_title</h2>\n<p>Trie une collection par titre (avec <a href=\"https://en.wikipedia.org/wiki/Natural_sort_order\" target=\"_blank\" rel=\"noopener noreferrer\">tri naturel</a>).</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ collection|sort_by_title }}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ site.pages|sort_by_title }}</span></code></pre>\n<h2 id=\"sort-by-date\">sort_by_date</h2>\n<p>Trie une collection par date (la plus récente en premier).</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ collection|sort_by_date(variable='<span class=\"hljs-name\">date</span>', desc_title=false) }}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-comment\">{# sort by date #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ site.pages|sort_by_date }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# sort by updated variable instead of date #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ site.pages|sort_by_date(variable='updated') }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# sort items with the same date by desc title #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ site.pages|sort_by_date(desc_title=true) }}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# reverse sort #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ site.pages|sort_by_date|<span class=\"hljs-keyword\">reverse</span> }}</span></code></pre>\n<h2 id=\"sort-by-weight\">sort_by_weight</h2>\n<p>Trie une collection par poids (le plus léger en premier).</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ collection|sort_by_weight }}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ site.menus.main|sort_by_weight }}</span></code></pre>\n<h2 id=\"sort\">sort</h2>\n<p>Pour les cas plus complexes, vous devez utiliser <a href=\"https://twig.symfony.com/doc/filters/sort.html\" target=\"_blank\" rel=\"noopener noreferrer\">le <code translate=\"no\">sort</code></a> natif de Twig.</p>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">set</span></span> files = site.static|<span class=\"hljs-keyword\">sort</span>((a, b) =&gt; a.<span class=\"hljs-name\">date</span>|<span class=\"hljs-keyword\">date</span>('U') &lt; b.<span class=\"hljs-name\">date</span>|<span class=\"hljs-keyword\">date</span>('U')) %}</span></code></pre>",
      "language": "fr"
    },
    {
      "id": "https://cecil.app/fr/documentation/templates/reference/filtres/",
      "url": "https://cecil.app/fr/documentation/templates/reference/filtres/",
      "title": "Filtres",
      "summary": "filter_by, markdown_to_html, toc, slugify, excerpt, highlight, preg_*, etc.",
      "date_published": "2026-05-26T00:00:00+00:00",
      "date_modified": "2026-10-05T00:00:00+00:00","content_text": "Filtres\nLes variables peuvent être modifiées par filtres. Les filtres sont séparés de la variable par un symbole de barre verticale (|). Plusieurs filtres peuvent être chaînés. La sortie d’un filtre est appliquée au suivant.\n{{ page.title|truncate(25)|capitalize }}\nfilter_by\nFiltre une collection de pages par nom\/valeur de variable.\n{{ collection|filter_by(variable, value) }}\nExemple:\n{{ pages|filter_by('section', 'blog') }}\nfilter\nPour les cas plus complexes, vous devez utiliser le filter natif de Twig.\nExemple:\n{% pages|filter(p =&gt; p.virtual == false and p.id not in ['page-1', 'page-2']) %}\nmarkdown_to_html\nConvertit une chaîne Markdown en HTML.\n{{ markdown|markdown_to_html }}\n{% apply markdown_to_html %}\n{# Markdown here #}\n{% endapply %}\nExemples :\n{% set markdown = '**This is bold text**' %}\n{{ markdown|markdown_to_html }}\n{% apply markdown_to_html %}\n**This is bold text**\n{% endapply %}\ntoc\nExtrait uniquement les en-têtes correspondant au selectors donné (h2, h3, etc.), ou à ceux définis dans la configuration pages.body.toc s'ils ne sont pas spécifiés.\nLe paramètre format définit le format de sortie : html ou json.\nLe paramètre url est utilisé pour créer des liens vers des titres.\n{{ markdown|toc(format, selectors, url) }}\nExemples :\n{{ page.body|toc }}\n{{ page.body|toc('html') }}\n{{ page.body|toc(selectors=['h2']) }}\n{{ page.body|toc(url=url(page)) }}\njson_decode\nConvertit une chaîne JSON en tableau.\n{{ json|json_decode }}\nExemple:\n{% set json = '{\"foo\": \"bar\"}' %}\n{% set array = json|json_decode %}\n{{ array.foo }}\nyaml_parse\nConvertit une chaîne YAML en tableau.\n{{ yaml|yaml_parse }}\nExemple:\n{% set yaml = 'key: value' %}\n{% set array = yaml|yaml_parse %}\n{{ array.key }}\nslugify\nConvertit une chaîne en slug.\n{{ string|slugify }}\nu\nLe filtre u enveloppe un texte dans un objet Unicode (une instance Symfony UnicodeString) qui expose des méthodes pour « manipuler » la chaîne.\nExemple:\n{{ 'cecil_string with twig'|u.camel.title }}\n\nCecilStringAvecTwig\n\nsingular\nLe filtre singular transforme un nom donné au pluriel en sa version singulière.\n{{ string|singular(locale)}}\nExemple:\n{# English (en) rules are used by default #}\n{{ 'partitions'|singular }}\n\npartition\n\n{{ 'partitions'|singular('fr') }}\n\npartition\n\nplural\nLe filtre plural transforme un nom donné au singulier en sa version plurielle.\n{{ string|plural(locale)}}\nExemple:\n{# English (en) rules are used by default #}\n{{ 'animal'|plural }}\n\nanimaux\n\n{{ 'animal'|plural('fr') }}\n\nanimaux\n\nexcerpt\nTronque une chaîne et ajoute un suffixe.\n{{ string|excerpt(length, suffix) }}\n\n\n\nOptions\nDescriptif\nTapez\nPar défaut\n\n\n\n\nlongueur\nTronque après ce nombre de caractères.\nentier\n450\n\n\nsuffixe\nAjoute des caractères.\nchaîne\n…\n\n\n\nExemples :\n{{ variable|excerpt }}\n{{ variable|excerpt(250, '...') }}\nexcerpt_html\nLit les caractères avant ou après la balise &lt;!-- excerpt --&gt; ou &lt;!-- break --&gt;.\nVoir Documentation de contenu pour plus de détails.\n{{ string|excerpt_html({separator, capture}) }}\n\n\n\nOptions\nDescriptif\nTapez\nPar défaut\n\n\n\n\nséparateur\nChaîne à utiliser comme séparateur.\nchaîne\nexcerpt|break\n\n\ncapturer\nPièce à capturer, before ou after le séparateur.\nchaîne\nbefore\n\n\n\nExemples :\n{{ variable|excerpt_html }}\n{{ variable|excerpt_html({separator: 'excerpt|break', capture: 'before'}) }}\n{{ variable|excerpt_html({capture: 'after'}) }}\nhighlight\nMet en surbrillance une chaîne de code avec highlight.php.\n{{ code|highlight(language) }}\nExemples :\n{{ '&lt;?php echo $highlighted-&gt;value; ?&gt;'|highlight('php') }}\npreg_split\nDivise une chaîne en un tableau à l'aide d'une expression régulière.\n{{ string|preg_split(pattern, limit) }}\nExemple:\n{% set headers = page.content|preg_split('\/&lt;br[^&gt;]*&gt;\/') %}\npreg_match_all\nEffectue une correspondance d'expression régulière et renvoie le groupe pour toutes les correspondances.\n{{ string|preg_match_all(pattern, group) }}\nExemple:\n{% set tags = page.content|preg_match_all('\/&lt;[^&gt;]+&gt;(.*)&lt;\\\/[^&gt;]+&gt;\/') %}\nhex_to_rgb\nConvertit une couleur hexadécimale en RVB.\n{{ color|hex_to_rgb }}",
      "content_html": "<h1>Filtres</h1>\n<p>Les variables peuvent être modifiées par <a href=\"https://twig.symfony.com/doc/filters/index.html\" target=\"_blank\" rel=\"noopener noreferrer\">filtres</a>. Les filtres sont séparés de la variable par un symbole de barre verticale (<code translate=\"no\">|</code>). Plusieurs filtres peuvent être chaînés. La sortie d’un filtre est appliquée au suivant.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ page.title|truncate(25)|<span class=\"hljs-keyword\">capitalize</span> }}</span></code></pre>\n<h2 id=\"filter-by\">filter_by</h2>\n<p>Filtre une collection de pages par nom/valeur de variable.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ collection|filter_by(variable, value) }}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ pages|filter_by('section', 'blog') }}</span></code></pre>\n<h2 id=\"filter\">filter</h2>\n<p>Pour les cas plus complexes, vous devez utiliser <a href=\"https://twig.symfony.com/doc/filters/filter.html\" target=\"_blank\" rel=\"noopener noreferrer\">le <code translate=\"no\">filter</code></a> natif de Twig.</p>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\">pages</span>|<span class=\"hljs-keyword\">filter</span>(p =&gt; p.virtual == false and p.id not in ['page-1', 'page-2']) %}</span></code></pre>\n<h2 id=\"markdown-to-html\">markdown_to_html</h2>\n<p>Convertit une chaîne Markdown en HTML.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ markdown|markdown_to_html }}</span></code></pre>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">apply</span></span> markdown_to_html %}</span><span class=\"xml\">\n</span><span class=\"hljs-comment\">{# Markdown here #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">endapply</span></span> %}</span></code></pre>\n<p><em>Exemples :</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">set</span></span> markdown = '**This is bold text**' %}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ markdown|markdown_to_html }}</span></code></pre>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">apply</span></span> markdown_to_html %}</span><span class=\"xml\">\n**This is bold text**\n</span><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">endapply</span></span> %}</span></code></pre>\n<h2 id=\"toc\">toc</h2>\n<p>Extrait uniquement les en-têtes correspondant au <code translate=\"no\">selectors</code> donné (h2, h3, etc.), ou à ceux définis dans la configuration <code translate=\"no\">pages.body.toc</code> s'ils ne sont pas spécifiés.\nLe paramètre <code translate=\"no\">format</code> définit le format de sortie : <code translate=\"no\">html</code> ou <code translate=\"no\">json</code>.\nLe paramètre <code translate=\"no\">url</code> est utilisé pour créer des liens vers des titres.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ markdown|toc(format, selectors, url) }}</span></code></pre>\n<p><em>Exemples :</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ page.body|toc }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ page.body|toc('html') }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ page.body|toc(selectors=['h2']) }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ page.body|toc(url=url(page)) }}</span></code></pre>\n<h2 id=\"json-decode\">json_decode</h2>\n<p>Convertit une chaîne JSON en tableau.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ json|json_decode }}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">set</span></span> json = '{\"foo\": \"bar\"}' %}</span><span class=\"xml\">\n</span><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">set</span></span> array = json|json_decode %}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ array.foo }}</span></code></pre>\n<h2 id=\"yaml-parse\">yaml_parse</h2>\n<p>Convertit une chaîne YAML en tableau.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ yaml|yaml_parse }}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">set</span></span> yaml = 'key: value' %}</span><span class=\"xml\">\n</span><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">set</span></span> array = yaml|yaml_parse %}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ array.key }}</span></code></pre>\n<h2 id=\"slugify\">slugify</h2>\n<p>Convertit une chaîne en slug.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ string|slugify }}</span></code></pre>\n<h2 id=\"u\">u</h2>\n<p>Le filtre <code translate=\"no\">u</code> enveloppe un texte dans un objet Unicode (une <a href=\"https://symfony.com/doc/current/components/string.html\" target=\"_blank\" rel=\"noopener noreferrer\">instance Symfony UnicodeString</a>) qui expose des méthodes pour « manipuler » la chaîne.</p>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ 'cecil_string with twig'|u.camel.title }}</span></code></pre>\n<blockquote>\n<p>CecilStringAvecTwig</p>\n</blockquote>\n<h2 id=\"singular\">singular</h2>\n<p>Le filtre <code translate=\"no\">singular</code> transforme un nom donné au pluriel en sa version singulière.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ string|singular(locale)}}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-comment\">{# English (en) rules are used by default #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ 'partitions'|singular }}</span></code></pre>\n<blockquote>\n<p>partition</p>\n</blockquote>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ 'partitions'|singular('fr') }}</span></code></pre>\n<blockquote>\n<p>partition</p>\n</blockquote>\n<h2 id=\"plural\">plural</h2>\n<p>Le filtre <code translate=\"no\">plural</code> transforme un nom donné au singulier en sa version plurielle.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ string|plural(locale)}}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-comment\">{# English (en) rules are used by default #}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ 'animal'|plural }}</span></code></pre>\n<blockquote>\n<p>animaux</p>\n</blockquote>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ 'animal'|plural('fr') }}</span></code></pre>\n<blockquote>\n<p>animaux</p>\n</blockquote>\n<h2 id=\"excerpt\">excerpt</h2>\n<p>Tronque une chaîne et ajoute un suffixe.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ string|excerpt(length, suffix) }}</span></code></pre>\n<table>\n<thead>\n<tr>\n<th>Options</th>\n<th>Descriptif</th>\n<th>Tapez</th>\n<th>Par défaut</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>longueur</td>\n<td>Tronque après ce nombre de caractères.</td>\n<td>entier</td>\n<td>450</td>\n</tr>\n<tr>\n<td>suffixe</td>\n<td>Ajoute des caractères.</td>\n<td>chaîne</td>\n<td><code translate=\"no\">…</code></td>\n</tr>\n</tbody>\n</table>\n<p><em>Exemples :</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ variable|excerpt }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ variable|excerpt(250, '...') }}</span></code></pre>\n<h2 id=\"excerpt-html\">excerpt_html</h2>\n<p>Lit les caractères avant ou après la balise <code translate=\"no\">&lt;!-- excerpt --&gt;</code> ou <code translate=\"no\">&lt;!-- break --&gt;</code>.\nVoir <a href=\"../../content/7-markdown.fr.md#extrait\">Documentation de contenu</a> pour plus de détails.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ string|excerpt_html({separator, capture}) }}</span></code></pre>\n<table>\n<thead>\n<tr>\n<th>Options</th>\n<th>Descriptif</th>\n<th>Tapez</th>\n<th>Par défaut</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>séparateur</td>\n<td>Chaîne à utiliser comme séparateur.</td>\n<td>chaîne</td>\n<td><code translate=\"no\">excerpt|break</code></td>\n</tr>\n<tr>\n<td>capturer</td>\n<td>Pièce à capturer, <code translate=\"no\">before</code> ou <code translate=\"no\">after</code> le séparateur.</td>\n<td>chaîne</td>\n<td><code translate=\"no\">before</code></td>\n</tr>\n</tbody>\n</table>\n<p><em>Exemples :</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ variable|excerpt_html }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ variable|excerpt_html({separator: 'excerpt|break', capture: 'before'}) }}</span><span class=\"xml\">\n</span><span class=\"hljs-template-variable\">{{ variable|excerpt_html({capture: 'after'}) }}</span></code></pre>\n<h2 id=\"highlight\">highlight</h2>\n<p>Met en surbrillance une chaîne de code avec <a href=\"https://github.com/scrivo/highlight.php\" target=\"_blank\" rel=\"noopener noreferrer\">highlight.php</a>.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ code|highlight(language) }}</span></code></pre>\n<p><em>Exemples :</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ '&lt;?php echo $highlighted-&gt;value; ?&gt;'|highlight('php') }}</span></code></pre>\n<h2 id=\"preg-split\">preg_split</h2>\n<p>Divise une chaîne en un tableau à l'aide d'une expression régulière.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ string|preg_split(pattern, limit) }}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">set</span></span> headers = page.content|preg_split('/&lt;br[^&gt;]*&gt;/') %}</span></code></pre>\n<h2 id=\"preg-match-all\">preg_match_all</h2>\n<p>Effectue une correspondance d'expression régulière et renvoie le groupe pour toutes les correspondances.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ string|preg_match_all(pattern, group) }}</span></code></pre>\n<p><em>Exemple:</em></p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-tag\">{% <span class=\"hljs-name\"><span class=\"hljs-keyword\">set</span></span> tags = page.content|preg_match_all('/&lt;[^&gt;]+&gt;(.*)&lt;\\/[^&gt;]+&gt;/') %}</span></code></pre>\n<h2 id=\"hex-to-rgb\">hex_to_rgb</h2>\n<p>Convertit une couleur hexadécimale en RVB.</p>\n<pre><code class=\"language-twig hljs twig\" translate=\"no\"><span class=\"hljs-template-variable\">{{ color|hex_to_rgb }}</span></code></pre>",
      "language": "fr"
    }
  ]
}
