mezzio / mezzio-twigrenderer
Twig integration for Mezzio
Fund package maintenance!
Community Bridge
Installs: 353 977
Dependents: 16
Suggesters: 5
Security: 0
Stars: 6
Watchers: 13
Forks: 9
Open Issues: 3
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- mezzio/mezzio-helpers: ^5.0
- mezzio/mezzio-router: ^3.7
- mezzio/mezzio-template: ^2.0
- psr/container: ^1.0 || ^2.0
- twig/twig: ^3.14.0
Requires (Dev)
- laminas/laminas-coding-standard: ~2.5.0
- phpunit/phpunit: ^10.5.33
- psalm/plugin-phpunit: ^0.19.0
- vimeo/psalm: ^5.26.1
Conflicts
- 2.17.x-dev
- 2.16.x-dev
- 2.16.0
- 2.15.x-dev
- 2.15.0
- 2.14.x-dev
- 2.14.0
- 2.13.x-dev
- 2.13.0
- 2.12.x-dev
- 2.12.0
- 2.11.x-dev
- 2.11.0
- 2.10.x-dev
- 2.10.0
- 2.9.x-dev
- 2.9.0
- 2.8.x-dev
- 2.8.0
- 2.7.x-dev
- 2.7.0
- 2.6.x-dev
- 2.6.1
- 2.6.0
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- 2.0.0rc1
- 2.0.0alpha1
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- 0.3.1
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1.0
- dev-renovate/lock-file-maintenance
- dev-renovate/phpunit-phpunit-11.x
This package is auto-updated.
Last update: 2024-10-07 04:18:33 UTC
README
π·πΊ Π ΡΡΡΠΊΠΈΠΌ Π³ΡΠ°ΠΆΠ΄Π°Π½Π°ΠΌ
ΠΡ, ΡΡΠ°ΡΡΠ½ΠΈΠΊΠΈ Laminas, ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ ΠΈ ΠΆΠΈΠ²Π΅ΠΌ Π² ΡΠ°Π·Π½ΡΡ ΡΡΡΠ°Π½Π°Ρ . Π£ ΠΌΠ½ΠΎΠ³ΠΈΡ ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΠΊΠΈ ΠΈ ΠΊΠΎΠ»Π»Π΅Π³ΠΈ ΠΊΠ°ΠΊ Π² Π ΠΎΡΡΠΈΠΈ, ΡΠ°ΠΊ ΠΈ Π² Π£ΠΊΡΠ°ΠΈΠ½Π΅. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ Π² Π ΠΎΡΡΠΈΠΈ. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΠΆΠΈΠ²ΡΡ Π² Π ΠΎΡΡΠΈΠΈ. Π£ Π½Π΅ΠΊΠΎΡΠΎΡΡΡ Π±Π°Π±ΡΡΠΊΠΈ ΠΈ Π΄Π΅Π΄ΡΡΠΊΠΈ ΡΡΠ°ΠΆΠ°Π»ΠΈΡΡ Ρ ΡΠ°ΡΠΈΡΡΠ°ΠΌΠΈ Π²ΠΎ ΠΡΠΎΡΠΎΠΉ ΠΌΠΈΡΠΎΠ²ΠΎΠΉ Π²ΠΎΠΉΠ½Π΅. ΠΠ΄Π΅ΡΡ Π½ΠΈΠΊΡΠΎ Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°Π΅Ρ ΡΠ°ΡΠΈΠ·ΠΌ.
Π£ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ ΡΠΊΡΠ°ΠΈΠ½ΡΠΊΠ°Ρ ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΡΠ°, ΠΊΠΎΡΠΎΡΠ°Ρ ΡΠΏΠ°ΡΠ»Π°ΡΡ ΠΈΠ· Π΄ΠΎΠΌΠ° Π²ΠΌΠ΅ΡΡΠ΅ Ρ ΡΡΠ½ΠΎΠΌ. ΠΠΎΠ΅Π·Π΄ Π·Π°Π΄Π΅ΡΠΆΠ°Π»ΡΡ ΠΈΠ·-Π·Π° Π±ΠΎΠΌΠ±Π΅ΠΆΠΊΠΈ Π½Π° Π΄ΠΎΡΠΎΠ³Π΅ Π²ΠΏΠ΅ΡΠ΅Π΄ΠΈ. Π£ Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΠΊΠΎΡΠΎΡΡΠ΅ ΠΏΡΡΡΡΡΡΡ Π² Π±ΠΎΠΌΠ±ΠΎΡΠ±Π΅ΠΆΠΈΡΠ°Ρ . ΠΡ Ρ ΡΡΠ΅Π²ΠΎΠ³ΠΎΠΉ ΠΆΠ΄Π΅ΠΌ Π²Π΅ΡΡΠΎΡΠΊΠΈ ΠΎΡ Π½ΠΈΡ ΠΏΠΎΡΠ»Π΅ Π²ΠΎΠ·Π΄ΡΡΠ½ΡΡ Π½Π°Π»Π΅ΡΠΎΠ², ΠΊΠΎΡΠΎΡΡΠ΅ Π±Π΅ΡΠΏΠΎΡΡΠ΄ΠΎΡΠ½ΠΎ Π½Π°Π½ΠΎΡΡΡ ΡΠ΄Π°ΡΡ ΠΈ ΠΏΠΎΠΏΠ°Π΄Π°ΡΡ ΠΏΠΎ Π±ΠΎΠ»ΡΠ½ΠΈΡΠ°ΠΌ, ΡΠΊΠΎΠ»Π°ΠΌ, Π΄Π΅ΡΡΠΊΠΈΠΌ ΡΠ°Π΄Π°ΠΌ ΠΈ Π΄ΠΎΠΌΠ°ΠΌ. ΠΡ Π½Π΅ Π±Π΅ΡΠ΅ΠΌ ΡΡΠΎ ΠΈΠ· ΠΊΠ°ΠΊΠΈΡ -Π»ΠΈΠ±ΠΎ Π‘ΠΠ. ΠΡ Π½Π°Π±Π»ΡΠ΄Π°Π΅ΠΌ ΡΡΠΎ Π½Π°ΠΏΡΡΠΌΡΡ.
ΠΡ Π΄ΠΎΠ²Π΅ΡΡΠ΅ΡΠ΅ Π½Π°ΠΌ Π΄ΠΎΡΡΠ°ΡΠΎΡΠ½ΠΎ, ΡΡΠΎΠ± ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ Π½Π°ΡΠΈ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ, ΠΈ ΠΌΡ ΠΏΡΠΎΡΠΈΠΌ Π²Π°Ρ Π΄ΠΎΠ²Π΅ΡΠΈΡΡΡΡ Π½Π°ΠΌ Π²Π½ΠΎΠ²Ρ. ΠΡ Π½ΡΠΆΠ΄Π°Π΅ΠΌΡΡ Π² ΠΏΠΎΠΌΠΎΡΠΈ. ΠΡΡ ΠΎΠ΄ΠΈΡΠ΅ ΠΈ ΠΏΡΠΎΡΠ΅ΡΡΡΠΉΡΠ΅ ΠΏΡΠΎΡΠΈΠ² ΡΡΠΎΠΉ Π±Π΅ΡΠΏΠΎΠ»Π΅Π·Π½ΠΎΠΉ Π²ΠΎΠΉΠ½Ρ. ΠΡΡΠ°Π½ΠΎΠ²ΠΈΡΠ΅ ΠΊΡΠΎΠ²ΠΎΠΏΡΠΎΠ»ΠΈΡΠΈΠ΅. Π‘ΠΊΠ°ΠΆΠΈΡΠ΅ "ΠΠ΅Ρ Π²ΠΎΠΉΠ½Π΅!"
πΊπΈ To Citizens of Russia
We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"
Provides Twig integration for Mezzio.
Installation
Install this library using composer:
$ composer require mezzio/mezzio-twigrenderer
We recommend using a dependency injection container, and typehint against container-interop. We can recommend the following implementations:
- laminas-servicemanager:
composer require laminas/laminas-servicemanager
- pimple-interop:
composer require mouf/pimple-interop
- Aura.Di:
composer require aura/di
Twig Extension
The included Twig extension adds support for url generation. The extension is automatically activated if the UrlHelper and ServerUrlHelper are registered with the container.
-
path
: Render the relative path for a given route and parameters. If there is no route, it returns the current path.{{ path('article_show', {'id': '3'}) }} Generates: /article/3
path
supports optional query parameters and a fragment identifier.{{ path('article_show', {'id': '3'}, {'foo': 'bar'}, 'fragment') }} Generates: /article/3?foo=bar#fragment
By default the current route result is used where applicable. To disable this the
reuse_result_params
option can be set.{{ path('article_show', {}, {}, null, {'reuse_result_params': false}) }}
-
url
: Render the absolute url for a given route and parameters. If there is no route, it returns the current url.{{ url('article_show', {'slug': 'article.slug'}) }} Generates: http://example.com/article/article.slug
url
also supports query parameters and a fragment identifier.{{ url('article_show', {'id': '3'}, {'foo': 'bar'}, 'fragment') }} Generates: http://example.com/article/3?foo=bar#fragment
By default the current route result is used where applicable. To disable this the
reuse_result_params
option can be set.{{ url('article_show', {}, {}, null, {'reuse_result_params': false}) }}
-
absolute_url
: Render the absolute url from a given path. If the path is empty, it returns the current url.{{ absolute_url('path/to/something') }} Generates: http://example.com/path/to/something
-
asset
Render an (optionally versioned) asset url.{{ asset('path/to/asset/name.ext', version=3) }} Generates: path/to/asset/name.ext?v=3
To get the absolute url for an asset:
{{ absolute_url(asset('path/to/asset/name.ext', version=3)) }} Generates: http://example.com/path/to/asset/name.ext?v=3
Configuration
If you use the laminas-component-installer the factories are configured automatically for you when requiring this package with composer. Without the component installer, you need to include the ConfigProvider
in your config/config.php
.
Optional configuration can be stored in config/autoload/templates.global.php
.
'templates' => [ 'extension' => 'file extension used by templates; defaults to html.twig', 'paths' => [ // namespace / path pairs // // Numeric namespaces imply the default/main namespace. Paths may be // strings or arrays of string paths to associate with the namespace. ], ], 'twig' => [ 'cache_dir' => 'path to cached templates', 'assets_url' => 'base URL for assets', 'assets_version' => 'base version for assets', 'extensions' => [ // extension service names or instances ], 'runtime_loaders' => [ // runtime loaders names or instances ], 'globals' => [ // Global variables passed to twig templates 'ga_tracking' => 'UA-XXXXX-X' ], 'timezone' => 'default timezone identifier, e.g.: America/New_York', 'optimizations' => -1, // -1: Enable all (default), 0: disable optimizations 'autoescape' => 'html', // Auto-escaping strategy [html|js|css|url|false] 'auto_reload' => true, // Recompile the template whenever the source code changes 'debug' => true, // When set to true, the generated templates have a toString() method 'strict_variables' => true, // When set to true, twig throws an exception on invalid variables ],
Documentation
See the Mezzio Twig documentation.