Skip to content

TangoMan TwigHelper Bundle provides a collection of useful twig functions.

License

Notifications You must be signed in to change notification settings

TangoMan75/TwigHelperBundle

Repository files navigation

TangoMan TwigHelper Bundle

TangoMan TwigHelper Bundle provides a collection of useful twig functions.

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require tangoman/twig-helper-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    // ...

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new TangoMan\TwigHelperBundle\TangoManTwigHelperBundle(),
        );

        // ...
    }
}

Availlable functions

start_with

(deprecated, since twig 3x handles this one just fine)

Checks if at least one item from haystack starts with needle.

{% if start_with(app.request.attributes.get('_route'), item.pages ?? []) %}
    {{ item }}
{% endif %}

end_with

(deprecated, since twig 3x handles this one just fine)

Checks if at least one item from haystack ends with needle.

{% if end_with(app.request.attributes.get('_route'), ['index','list']) %}
    {{ item }}
{% endif %}

is_numeric

Finds whether a variable is a number or a numeric string.

{% if is_numeric(item) %}
    {{ item }}
{% else %}
    "{{ item }}"
{% endif %}

is_string

Find whether the type of a variable is string.

{% if is_string(user) %}
    Welcome {{ user }} !
{% else %}
    Are you kidding me ? Is "{{ user }}" even a name ?
{% endif %}

Availlable filters

to_array

Converts stdObject or json string to traversable array.

{% for key, value in object|to_array %}
    <td>{{ key }}</td>
    <td>{{ value }}</td>
{% endif %}

Note

If you find any bug please report here : Issues

License

Copyright (c) 2020 Matthias Morin

License Distributed under the MIT license.

If you like TangoMan TwigHelper Bundle please star! And follow me on GitHub: TangoMan75 ... And check my other cool projects.

Matthias Morin | LinkedIn

About

TangoMan TwigHelper Bundle provides a collection of useful twig functions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages