Ajouter une fonction à twig dans Timber.

PHP
                    <?php
/**
 * Adds functionality to Twig.
 * 
 * @param \Twig\Environment $twig The Twig environment.
 * @return \Twig\Environment
 */
function undfnd_add_twig_functions( $twig ) {
    // Ajouter des fonctions.
    $twig->addFunction( new Timber\Twig_Function( 'custom_function', 'custom_function' ) ); // {{ custom_function(post.title) }}
    $twig->addFunction( new Timber\Twig_Function( 'sanitize_title', 'sanitize_title' ) ); // {{ sanitize_title(post.title) }}
    
    return $twig;
}
add_filter( 'timber/twig', 'undfnd_add_twig_functions' );

function custom_function( $text ) {
    // votre code
    return $text;
}