tangoman/twig-helper-bundle

There is no license information available for the latest version (1.0.2) of this package.

Symfony TwigHelper Twig Extension Bundle

Installs: 110

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.0.2 2018-04-08 21:21 UTC

This package is auto-updated.

Last update: 2024-05-05 03:07:13 UTC


README

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