PHP code example of jorisnoo / craft-twig-helpers

1. Go to this page and download the library: Download jorisnoo/craft-twig-helpers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jorisnoo / craft-twig-helpers example snippets


return [
    'modules' => [
        'twig-helpers' => \Noo\CraftTwigHelpers\TwigHelpers::class,
    ],
    'bootstrap' => ['twig-helpers'],
];

use Noo\CraftTwigHelpers\config\TwigHelpersConfig;

return TwigHelpersConfig::create()
    ->filters([
        'myFilter' => fn (string $value) => strtoupper($value),
    ])
    ->functions([
        'myFunction' => fn () => 'Hello, world!',
    ])
    ->globals([
        'siteName' => 'My Site',
    ])
    ->tests([
        'even' => fn (int $value) => $value % 2 === 0,
    ]);