ravenflux/php-functions

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.
This package is abandoned and no longer maintained. No replacement package was suggested.

Twig extension that implements a way to use native PHP functions and filters in Twig template

This package has no released version yet, and little information is available.


README

Latest Stable Version Latest Unstable Version License Total Downloads

ravenflux.jpg

Twig extension that implements a way to use native PHP functions and filters in Twig template.

Medium article

Installation

The recommended way to install is via Composer:

composer require ravenflux/php-functions

This package requires at least PHP 8.0.0

For Symfony usage add it as a service and tag it:

# config/services.yaml
services:
    ravenflux.twig.extension.php_functions:
        class: RavenFlux\Php\PhpFunctionsExtension
        arguments:
            - #first argument are functions
                - 'count'
            - #second argument are filters
                - 'nl2br'
        tags:
            -
                name: twig.extension

or without any arguments if you want to use dynamic function / filters:

# config/services.yaml
services:
    ravenflux.twig.extension.php_functions:
        class: RavenFlux\Php\PhpFunctionsExtension
        tags:
            -
                name: twig.extension

Function VS Filter | source

A function is used when you need to compute things to render the result.
A filter is a way to transform the displayed data.

Usage

Functions:

{{ count(users) }}

Filters:

{{ user.name|nl2br }}

or dynamically any php function:

Functions:

{{ raven_function('count', users) }}

Filters:

{{ user.name|raven_filter('nl2br') }}