PHP code example of danilovl / render-service-twig-extension-bundle

1. Go to this page and download the library: Download danilovl/render-service-twig-extension-bundle 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/ */

    

danilovl / render-service-twig-extension-bundle example snippets


 declare(strict_types=1);

namespace App\Application\Controller;

use Danilovl\RenderServiceTwigExtensionBundle\Attribute\AsTwigFunction;

#[AsTwigFunction('math_')]
class CountService
{
    public function sum(int $one, int $two): int
    {
        return $one + $two;
    }

    public function min(int $one, int $two): int
    {
        return $one - $two;
    }

    public function multiplicationOperation(int $one, int $two): int
    {
        return $one * $two;
    }
}

 declare(strict_types=1);

namespace App\Application\Controller;

use Danilovl\RenderServiceTwigExtensionBundle\Attribute\{
    AsTwigFilter,
    AsTwigFunction
};

class RenderServiceController
{
    #[AsTwigFunction('function_sum')]
    public function twigFunctionSum(int $one, int $two): int
    {
        return $one + $two;
    }

    #[AsTwigFilter('filter_upper')]
    public function twigFilterUpper(string $text): string
    {
        return strtoupper($text);
    }
}
 php

// config/bundles.php

return [
    // ...
    Danilovl\RenderServiceTwigExtensionBundle\RenderServiceTwigExtensionBundle::class => ['all' => true]
];
twig
{{ 'text' | app_filter_upper }}
{{ app_function_sum(2,3) }}