TangoMan TwigHelper Bundle
TangoMan TwigHelper Bundle provides a collection of useful twig functions., (*1)
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:, (*2)
$ 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., (*3)
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:, (*4)
<?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), (*5)
Checks if at least one item from haystack starts with needle., (*6)
{% if start_with(app.request.attributes.get('_route'), item.pages ?? []) %}
{{ item }}
{% endif %}
end_with
(deprecated, since twig 3x handles this one just fine), (*7)
Checks if at least one item from haystack ends with needle., (*8)
{% 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., (*9)
{% if is_numeric(item) %}
{{ item }}
{% else %}
"{{ item }}"
{% endif %}
is_string
Find whether the type of a variable is string., (*10)
{% 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., (*11)
{% for key, value in object|to_array %}
<td>{{ key }}</td>
<td>{{ value }}</td>
{% endif %}
Note
If you find any bug please report here : Issues, (*12)
License
Copyright (c) 2020 Matthias Morin, (*13)
Distributed under the MIT license., (*14)
If you like TangoMan TwigHelper Bundle please star!
And follow me on GitHub: TangoMan75
... And check my other cool projects., (*15)
Matthias Morin | LinkedIn, (*16)