Les hooks pour Timber.

Timber est une surcouche WordPress destiné à améliorer la qualité de développement de vos thèmes. Voici tous les hooks disponibles pour Timber.

Ajouter un filtre à twig dans Timber

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

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

Ajouter une fonction à twig

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;
}