PHP code example of craue / twigextensions-bundle
1. Go to this page and download the library: Download craue/twigextensions-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
craue / twigextensions-bundle example snippets
// in config/bundles.php
return [
// ...
Craue\TwigExtensionsBundle\CraueTwigExtensionsBundle::class => ['all' => true],
];
// in app/AppKernel.php
public function registerBundles() {
$bundles = [
// ...
new Craue\TwigExtensionsBundle\CraueTwigExtensionsBundle(),
];
// ...
}
twig
{{ somevalue | craue_default }}
twig
{{ someValueWhichMayBeEmpty | craue_default }}<br />
{{ someValueWhichMayBeEmpty | craue_default('no value') }}<br />
{{ someValueWhichMayBeEmpty | craue_default('–') }}<br />
{{ someValueWhichMayBeEmpty | craue_default(0) }}
twig
{% for myEntity in myEntities %}
{% set myFormInstance = craue_cloneForm(myForm) %}
<form action="{{ path('my_route', {'id': myEntity.getId()}) }}" method="post" {{ form_enctype(myFormInstance) }}>
{{ form_widget(myFormInstance) }}
<input type="submit" />
</form>
{% endfor %}
twig
<h2>with the current locale</h2>
date: {{ someDateTimeValue | craue_date }}<br />
time: {{ someDateTimeValue | craue_time }}<br />
both: {{ someDateTimeValue | craue_datetime }}
<h2>with a specific locale</h2>
date: {{ someDateTimeValue | craue_date('de-DE') }}<br />
time: {{ someDateTimeValue | craue_time('de') }}<br />
both: {{ someDateTimeValue | craue_datetime('en-GB') }}
twig
<h2>with the current locale</h2>
thousands separator: {{ someNumber | craue_number }}<br />
default currency: {{ someNumber | craue_currency }}<br />
specific currency: {{ someNumber | craue_currency('EUR') }}<br />
spelled out number: {{ someNumber | craue_spellout }}
<h2>with a specific locale</h2>
thousands separator: {{ someNumber | craue_number('de-DE') }}<br />
default currency: {{ someNumber | craue_currency(null, 'de-DE') }}<br />
specific currency: {{ someNumber | craue_currency('EUR', 'de-DE') }}<br />
spelled out number: {{ someNumber | craue_spellout('de-DE') }}
xml
<!-- in app/config/parameters.xml -->
<parameter key="craue_twig_extensions.changeLanguage.availableLocales" type="collection">
<parameter key="de_DE">de</parameter>
<parameter key="en">en</parameter>
<parameter key="ru">ru</parameter>
</parameter>
twig
{{ somevalue | craue_default }}