<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://cecil.app/fr/xsl/atom.xsl" media="all"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">
  <id>https://cecil.app/fr/documentation/templates/reference/</id>
  <title>Cecil - Fonctions et filtres</title>
  <subtitle><![CDATA[Cecil est une application PHP en ligne de commande qui fusionne des pages Markdown, des médias et des templates Twig afin de générer un site Web statique.]]></subtitle>
  <link href="https://cecil.app/fr/documentation/templates/reference/atom.xml" rel="self" type="application/atom+xml" />
  <link href="https://cecil.app/fr/documentation/templates/reference/" rel="alternate" type="text/html" />
  <updated>2026-10-06T00:34:28+00:00</updated>
  <author>
    <name>Cecil</name>
    <uri>https://cecil.app</uri>
  </author>
  <entry xml:lang="fr">
    <id>https://cecil.app/fr/documentation/templates/reference/fonctions/</id>
    <title>Fonctions</title>
    <published>2026-05-26T00:00:00+00:00</published>
    <updated>2026-10-05T00:00:00+00:00</updated>
    <link href="https://cecil.app/fr/documentation/templates/reference/fonctions/" rel="alternate" type="text/html" />
    <content type="html">
      <![CDATA[<h1>Fonctions</h1>
<blockquote>
<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>
</blockquote>
<h2 id="url">url</h2>
<p>Crée une URL valide pour une page, une entrée de menu, un actif, un ID de page ou un chemin.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ url(value, {options}) }}</span></code></pre>
<table>
<thead>
<tr>
<th>Options</th>
<th>Descriptif</th>
<th>Tapez</th>
<th>Par défaut</th>
</tr>
</thead>
<tbody>
<tr>
<td>canonique</td>
<td>Préfixez l'URL avec <a href="/fr/documentation/configuration/site/#baseurl"><code translate="no">baseurl</code></a> ou utilisez <a href="/fr/documentation/configuration/site/#options-metatags"><code translate="no">canonical.url</code></a> s'il existe.</td>
<td>booléen</td>
<td><code translate="no">false</code></td>
</tr>
<tr>
<td>formats</td>
<td>Définit la page <a href="/fr/documentation/configuration/sortie/#output-formats">format de sortie</a> (par exemple : <code translate="no">json</code>).</td>
<td>chaîne</td>
<td><code translate="no">html</code></td>
</tr>
<tr>
<td>langue</td>
<td>Définit la page <a href="/fr/documentation/configuration/langues/#language">langue</a> (ex. : <code translate="no">fr</code>).</td>
<td>chaîne</td>
<td>nul</td>
</tr>
</tbody>
</table>
<p><em>Exemples :</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-comment">{# page #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ url(page) }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ url(page, {canonical: true}) }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ url(page, {format: json}) }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ url(page, {language: fr}) }}</span><span class="xml">
</span><span class="hljs-comment">{# menu entry #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ url(site.menus.main.about) }}</span><span class="xml">
</span><span class="hljs-comment">{# asset #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ url(asset('styles.css')) }}</span><span class="xml">
</span><span class="hljs-comment">{# page ID #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ url('page-id') }}</span><span class="xml">
</span><span class="hljs-comment">{# path #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ url('about-me/') }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ url('tags/' ~ tag) }}</span></code></pre>
<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>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-comment">{# page #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ page|url }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ page|url({canonical: true, format: json, language: fr}) }}</span><span class="xml">
</span><span class="hljs-comment">{# asset #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ asset('styles.css')|url }}</span></code></pre></aside>
<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>
<h2 id="html">html</h2>
<p>Crée un élément HTML à partir d'un actif (ou d'un tableau d'actifs avec des attributs personnalisés).</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ html(asset, {attributes}, {options}) }}</span><span class="xml">
</span><span class="hljs-comment">{# dedicated functions for each common type of asset #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ css(asset) }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ js(asset) }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ image(asset) }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ audio(asset) }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ video(asset) }}</span></code></pre>
<table>
<thead>
<tr>
<th>Options</th>
<th>Descriptif</th>
<th>Tapez</th>
</tr>
</thead>
<tbody>
<tr>
<td>attributs</td>
<td>Ajoute le couple <code translate="no">name="value"</code> à l'élément HTML.</td>
<td>tableau</td>
</tr>
<tr>
<td>options</td>
<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>
<td>tableau</td>
</tr>
</tbody>
</table>
<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>
<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="/fr/documentation/configuration/layouts/#layouts-images">configuration des layouts</a>.
Lorsque <a href="/fr/documentation/configuration/layouts/#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>.
De la même manière, lorsque <a href="/fr/documentation/configuration/layouts/#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="/fr/documentation/configuration/layouts/#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>
<p><em>Exemples :</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-comment">{# CSS with an attribute #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ html(asset('print.css'), {media: 'print'}) }}</span><span class="xml">
</span><span class="hljs-comment">{# CSS with an attribute and an option #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ html(asset('styles.css'), {title: 'Main theme'}, {preload: true}) }}</span><span class="xml">
</span><span class="hljs-comment">{# Array of assets with media query #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ html([
  {asset: asset('css/style.css')},
  {asset: asset('css/style-dark.css'), attributes: {media: '(prefers-color-scheme: dark)'}}</span><span class="xml">
]) }}
</span><span class="hljs-comment">{# JavaScript #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ html(asset('script.js')) }}</span><span class="xml">
</span><span class="hljs-comment">{# image without specific attributes nor options #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ html(asset('image.png')) }}</span><span class="xml">
</span><span class="hljs-comment">{# image with specific attributes, responsive images and alternative formats #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ html(asset('image.jpg'), {alt: 'Description', loading: 'lazy'}, {responsive: true, formats: ['avif', 'webp']}) }}</span><span class="xml">
</span><span class="hljs-comment">{# image with responsive pixels density images #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ html(asset('image.jpg'), options={responsive: 'density'}, attributes={width: 256}) }}</span><span class="xml">
</span><span class="hljs-comment">{# image with a Low-Quality Image Placeholder #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ html(asset('image.jpg'), {alt: 'Description', loading: 'lazy'}, {placeholder: 'lqip'}) }}</span><span class="xml">
</span><span class="hljs-comment">{# Audio #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ html(asset('audio.mp3')) }}</span><span class="xml">
</span><span class="hljs-comment">{# Video #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ html(asset('video.mp4')) }}</span></code></pre>
<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>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ asset|html({attributes}, {options}) }}</span></code></pre></aside>
<h2 id="readtime">readtime</h2>
<p>Détermine le temps de lecture d'un texte, en minutes.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ readtime(value) }}</span></code></pre>
<p><em>Exemple:</em></p>
<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>
<h2 id="hash">hash</h2>
<p>Calcule le hachage d'un objet, d'un tableau ou d'une chaîne avec un algorithme donné.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ hash(value, algorithm) }}</span></code></pre>
<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>
<p><em>Exemple:</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ hash('my string', 'sha256') }}</span></code></pre>
<h2 id="cache-key">cache_key</h2>
<p>Calcule une clé de cache pour <a href="/fr/documentation/templates/cache/#fragments-de-cache"><em>fragments</em> cache</a> en fonction d'un nom et d'une valeur facultative.</p>
<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">
  </span><span class="hljs-comment">{# cacheable content #}</span><span class="xml">
</span><span class="hljs-template-tag">{% <span class="hljs-name">endcache</span> %}</span></code></pre>
<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>
<h2 id="getenv">getenv</h2>
<p>Obtient la valeur d'une variable d'environnement à partir de sa clé.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ getenv(var) }}</span></code></pre>
<p><em>Exemple:</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ getenv('VAR') }}</span></code></pre>
<h2 id="dump">dump</h2>
<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>
<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>
<aside class="note note-important"><p>Le <a href="/fr/documentation/configuration/site/#debug"><em>debug mode</em></a> doit être activé.</p></aside>
<h2 id="d">d</h2>
<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>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ d(variable, {theme: light}) }}</span></code></pre>
<ul>
<li>Si <em>variable</em> n'est pas fourni, la fonction renvoie le contexte Twig actuel</li>
<li>Les thèmes disponibles sont « clair » (par défaut) et « sombre »</li>
</ul>
<aside class="note note-important"><p>Le <a href="/fr/documentation/configuration/site/#debug"><em>debug mode</em></a> doit être activé.</p></aside>]]>
    </content>
  </entry>
  <entry xml:lang="fr">
    <id>https://cecil.app/fr/documentation/templates/reference/tris/</id>
    <title>Tris</title>
    <published>2026-05-26T00:00:00+00:00</published>
    <updated>2026-10-05T00:00:00+00:00</updated>
    <link href="https://cecil.app/fr/documentation/templates/reference/tris/" rel="alternate" type="text/html" />
    <content type="html">
      <![CDATA[<h1>Tris</h1>
<p>Tri des collections (de pages, menus ou taxonomies).</p>
<h2 id="sort-by-title">sort_by_title</h2>
<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>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ collection|sort_by_title }}</span></code></pre>
<p><em>Exemple:</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ site.pages|sort_by_title }}</span></code></pre>
<h2 id="sort-by-date">sort_by_date</h2>
<p>Trie une collection par date (la plus récente en premier).</p>
<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>
<p><em>Exemple:</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-comment">{# sort by date #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ site.pages|sort_by_date }}</span><span class="xml">
</span><span class="hljs-comment">{# sort by updated variable instead of date #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ site.pages|sort_by_date(variable='updated') }}</span><span class="xml">
</span><span class="hljs-comment">{# sort items with the same date by desc title #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ site.pages|sort_by_date(desc_title=true) }}</span><span class="xml">
</span><span class="hljs-comment">{# reverse sort #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ site.pages|sort_by_date|<span class="hljs-keyword">reverse</span> }}</span></code></pre>
<h2 id="sort-by-weight">sort_by_weight</h2>
<p>Trie une collection par poids (le plus léger en premier).</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ collection|sort_by_weight }}</span></code></pre>
<p><em>Exemple:</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ site.menus.main|sort_by_weight }}</span></code></pre>
<h2 id="sort">sort</h2>
<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>
<p><em>Exemple:</em></p>
<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>]]>
    </content>
  </entry>
  <entry xml:lang="fr">
    <id>https://cecil.app/fr/documentation/templates/reference/filtres/</id>
    <title>Filtres</title>
    <published>2026-05-26T00:00:00+00:00</published>
    <updated>2026-10-05T00:00:00+00:00</updated>
    <link href="https://cecil.app/fr/documentation/templates/reference/filtres/" rel="alternate" type="text/html" />
    <content type="html">
      <![CDATA[<h1>Filtres</h1>
<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>
<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>
<h2 id="filter-by">filter_by</h2>
<p>Filtre une collection de pages par nom/valeur de variable.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ collection|filter_by(variable, value) }}</span></code></pre>
<p><em>Exemple:</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ pages|filter_by('section', 'blog') }}</span></code></pre>
<h2 id="filter">filter</h2>
<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>
<p><em>Exemple:</em></p>
<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>
<h2 id="markdown-to-html">markdown_to_html</h2>
<p>Convertit une chaîne Markdown en HTML.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ markdown|markdown_to_html }}</span></code></pre>
<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">
</span><span class="hljs-comment">{# Markdown here #}</span><span class="xml">
</span><span class="hljs-template-tag">{% <span class="hljs-name"><span class="hljs-keyword">endapply</span></span> %}</span></code></pre>
<p><em>Exemples :</em></p>
<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">
</span><span class="hljs-template-variable">{{ markdown|markdown_to_html }}</span></code></pre>
<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">
**This is bold text**
</span><span class="hljs-template-tag">{% <span class="hljs-name"><span class="hljs-keyword">endapply</span></span> %}</span></code></pre>
<h2 id="toc">toc</h2>
<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.
Le paramètre <code translate="no">format</code> définit le format de sortie : <code translate="no">html</code> ou <code translate="no">json</code>.
Le paramètre <code translate="no">url</code> est utilisé pour créer des liens vers des titres.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ markdown|toc(format, selectors, url) }}</span></code></pre>
<p><em>Exemples :</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ page.body|toc }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ page.body|toc('html') }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ page.body|toc(selectors=['h2']) }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ page.body|toc(url=url(page)) }}</span></code></pre>
<h2 id="json-decode">json_decode</h2>
<p>Convertit une chaîne JSON en tableau.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ json|json_decode }}</span></code></pre>
<p><em>Exemple:</em></p>
<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">
</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">
</span><span class="hljs-template-variable">{{ array.foo }}</span></code></pre>
<h2 id="yaml-parse">yaml_parse</h2>
<p>Convertit une chaîne YAML en tableau.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ yaml|yaml_parse }}</span></code></pre>
<p><em>Exemple:</em></p>
<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">
</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">
</span><span class="hljs-template-variable">{{ array.key }}</span></code></pre>
<h2 id="slugify">slugify</h2>
<p>Convertit une chaîne en slug.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ string|slugify }}</span></code></pre>
<h2 id="u">u</h2>
<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>
<p><em>Exemple:</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ 'cecil_string with twig'|u.camel.title }}</span></code></pre>
<blockquote>
<p>CecilStringAvecTwig</p>
</blockquote>
<h2 id="singular">singular</h2>
<p>Le filtre <code translate="no">singular</code> transforme un nom donné au pluriel en sa version singulière.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ string|singular(locale)}}</span></code></pre>
<p><em>Exemple:</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-comment">{# English (en) rules are used by default #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ 'partitions'|singular }}</span></code></pre>
<blockquote>
<p>partition</p>
</blockquote>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ 'partitions'|singular('fr') }}</span></code></pre>
<blockquote>
<p>partition</p>
</blockquote>
<h2 id="plural">plural</h2>
<p>Le filtre <code translate="no">plural</code> transforme un nom donné au singulier en sa version plurielle.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ string|plural(locale)}}</span></code></pre>
<p><em>Exemple:</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-comment">{# English (en) rules are used by default #}</span><span class="xml">
</span><span class="hljs-template-variable">{{ 'animal'|plural }}</span></code></pre>
<blockquote>
<p>animaux</p>
</blockquote>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ 'animal'|plural('fr') }}</span></code></pre>
<blockquote>
<p>animaux</p>
</blockquote>
<h2 id="excerpt">excerpt</h2>
<p>Tronque une chaîne et ajoute un suffixe.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ string|excerpt(length, suffix) }}</span></code></pre>
<table>
<thead>
<tr>
<th>Options</th>
<th>Descriptif</th>
<th>Tapez</th>
<th>Par défaut</th>
</tr>
</thead>
<tbody>
<tr>
<td>longueur</td>
<td>Tronque après ce nombre de caractères.</td>
<td>entier</td>
<td>450</td>
</tr>
<tr>
<td>suffixe</td>
<td>Ajoute des caractères.</td>
<td>chaîne</td>
<td><code translate="no">…</code></td>
</tr>
</tbody>
</table>
<p><em>Exemples :</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ variable|excerpt }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ variable|excerpt(250, '...') }}</span></code></pre>
<h2 id="excerpt-html">excerpt_html</h2>
<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>.
Voir <a href="/fr/documentation/contenu/markdown/#extrait">Documentation de contenu</a> pour plus de détails.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ string|excerpt_html({separator, capture}) }}</span></code></pre>
<table>
<thead>
<tr>
<th>Options</th>
<th>Descriptif</th>
<th>Tapez</th>
<th>Par défaut</th>
</tr>
</thead>
<tbody>
<tr>
<td>séparateur</td>
<td>Chaîne à utiliser comme séparateur.</td>
<td>chaîne</td>
<td><code translate="no">excerpt|break</code></td>
</tr>
<tr>
<td>capturer</td>
<td>Pièce à capturer, <code translate="no">before</code> ou <code translate="no">after</code> le séparateur.</td>
<td>chaîne</td>
<td><code translate="no">before</code></td>
</tr>
</tbody>
</table>
<p><em>Exemples :</em></p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ variable|excerpt_html }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ variable|excerpt_html({separator: 'excerpt|break', capture: 'before'}) }}</span><span class="xml">
</span><span class="hljs-template-variable">{{ variable|excerpt_html({capture: 'after'}) }}</span></code></pre>
<h2 id="highlight">highlight</h2>
<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>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ code|highlight(language) }}</span></code></pre>
<p><em>Exemples :</em></p>
<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>
<h2 id="preg-split">preg_split</h2>
<p>Divise une chaîne en un tableau à l'aide d'une expression régulière.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ string|preg_split(pattern, limit) }}</span></code></pre>
<p><em>Exemple:</em></p>
<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>
<h2 id="preg-match-all">preg_match_all</h2>
<p>Effectue une correspondance d'expression régulière et renvoie le groupe pour toutes les correspondances.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ string|preg_match_all(pattern, group) }}</span></code></pre>
<p><em>Exemple:</em></p>
<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>
<h2 id="hex-to-rgb">hex_to_rgb</h2>
<p>Convertit une couleur hexadécimale en RVB.</p>
<pre><code class="language-twig hljs twig" translate="no"><span class="hljs-template-variable">{{ color|hex_to_rgb }}</span></code></pre>]]>
    </content>
  </entry>
</feed>
