Download the PHP package craue/twigextensions-bundle without Composer
On this page you can find all versions of the php package craue/twigextensions-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download craue/twigextensions-bundle
More information about craue/twigextensions-bundle
Files in craue/twigextensions-bundle
Package twigextensions-bundle
Short Description Useful Twig extensions for your Symfony project.
License MIT
Homepage https://github.com/craue/TwigExtensionsBundle
Informations about the package twigextensions-bundle
Information
TwigExtensionsBundle is a collection of useful Twig extensions for your Symfony project.
A live demo with code examples can is available at http://craue.de/symfony-playground/en/CraueTwigExtensions/.
DecorateEmptyValueExtension
Provides an enhanced default
filter, craue_default
, to decorate empty values with a placeholder which can even be
HTML.
Usually, if you want to use HTML, e.g. the HTML entity —
, as value for the default filter in an HTML Twig
template you have to do cumbersome
to make it render properly. With this extension you can write
instead.
ArrayHelperExtension
Provides the filters
craue_without
wrapping PHP'sarray_diff
function,craue_replaceKey
which adds/replaces an array entry (whereupon the key can be a variable),craue_removeKey
which removes an array entry by key (whereupon the key can be a variable), andcraue_translateArray
which translates all entries in an array.
FormExtension
Provides a mechanism to render a form several times on one page. This is done by cloning the form prior to rendering
using the craue_cloneForm
function.
StringHelperExtension
Provides the craue_trailingDot
filter for ensuring that a text ends with a dot.
This comes in handy when using error messages (e.g. for validation) of vendor bundles (which are written like sentences
but are missing the trailing dots) together with your own ones (which should include the trailing dot).
FormatDateTimeExtension
Provides the filters craue_date
, craue_time
, and craue_datetime
for locale-aware formatting of date, time, and
date/time values.
FormatNumberExtension
Provides the filters craue_number
, craue_currency
, and craue_spellout
for locale-aware formatting of numbers and
currencies.
ChangeLanguageExtension
Provides the functions craue_languageName
and craue_availableLocales
as well as a template for implementing a
language change mechanism.
Installation
Get the bundle
Let Composer download and install the bundle by running
in a shell.
Enable the bundle
If you don't use Symfony Flex, register the bundle manually:
Or, for Symfony 3.4:
Examples to use the extensions in your Twig template
DecorateEmptyValueExtension
ArrayHelperExtension
FormExtension
StringHelperExtension
FormatDateTimeExtension
FormatNumberExtension
ChangeLanguageExtension
There's a Twig template provided which you can use to render a "change language" menu like this:
This will render a list of links to the current route in all defined languages. Wrap it in a div to style it via CSS. Take a look at the template if you want to customize it.
Set/override default values
DecorateEmptyValueExtension
FormatDateTimeExtension
FormatNumberExtension
ChangeLanguageExtension
You can also set the keys to be more specific about the locales:
Advanced stuff
Aliases
Optionally, you can define aliases for all provided filters/functions to be used within your project. This allows you to use names you prefer instead of the pre-defined ones. E.g., if you don't like to write
all the time, you may define an alias like d
for the craue_default
filter which allows you to write
in your Twig templates. But pay attention to not accidentally override built-in filters/functions, although you can do it intentionally.
DecorateEmptyValueExtension
ArrayHelperExtension
FormExtension
StringHelperExtension
FormatDateTimeExtension
FormatNumberExtension
ChangeLanguageExtension
Enabling only specific extensions
By default, all provided extensions are enabled. If you're using only one or some of them, you may want to disable the others. The following enables them all, so remove the ones you don't need:
All versions of twigextensions-bundle with dependencies
symfony/config Version ~4.4|~5.3|^6
symfony/dependency-injection Version ~4.4|~5.3|^6
symfony/twig-bundle Version ~4.4|~5.3|^6