TangoMan TwigHelper Bundle provides a collection of useful twig functions.
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.
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(),
);
// ...
}
}
(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 %}
(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 %}
Finds whether a variable is a number or a numeric string.
{% if is_numeric(item) %}
{{ item }}
{% else %}
"{{ item }}"
{% endif %}
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 %}
Converts stdObject or json string to traversable array.
{% for key, value in object|to_array %}
<td>{{ key }}</td>
<td>{{ value }}</td>
{% endif %}
If you find any bug please report here : Issues
Copyright (c) 2020 Matthias Morin
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.