danilovl / static-container-twig-extension-bundle
Symfony twig extension bundle provide sharing data between templates
Installs: 88
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.3
- symfony/framework-bundle: ^7.0
- symfony/twig-bundle: ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.0.1
- phpstan/phpstan-symfony: ^2.0.0
- phpunit/phpunit: ^10.2
README
StaticContainerTwigExtensionBundle
About
Twig extension provide sharing data between templates.
Requirements
- PHP 8.3 or higher
- Symfony 7.0 or higher
1. Installation
Install danilovl/static-container-twig-extension-bundle
package by Composer:
composer require danilovl/static-container-twig-extension-bundle
Add the StaticContainerTwigExtensionBundle to your application's bundles if does not add automatically:
<?php // config/bundles.php return [ // ... Danilovl\StaticContainerTwigExtensionBundle\StaticContainerTwigExtensionBundle::class => ['all' => true] ];
2. Usage
Create some key with value.
{# templates/first.html.twig #} {{ static_container_create('key', true) }} {{ static_container_create('keyObject', object) }} {{ static_container_create('keyArray', {'one': 1, 'two': 2}) }} {{ static_container_create('keyWithDefaultValueNull') }} {{ static_container_create('keyCounter', 1) }}
Control if the key exists in another template.
{# templates/second.html.twig #} {% if static_container_has('keyCounter') == true %} {{ static_container_update('keyCounter', 2) }} {% endif %}
Control if the key exists and print it.
{# templates/third.html.twig #} {% if static_container_has('keyCounter') == true %} {{ static_container_get('keyCounter') }} {% endif %}
Remove key.
{# templates/third.html.twig #} {{ static_container_remove('sameKey') }}
License
The ApplyFilterTwigExtensionBundle is open-sourced software licensed under the MIT license.