Twig extensions plugin adds new filters and functions to your templates! No other plugin dependencies.
There are two versions of this plugin: version 1 for October 1.0.x, 1.1.x, 2.0.x and version 2 for October 3.1.x. Below you can find documentation for both versions.
Version 2 for October 3.1.x
Available functions
session, trans, var_dump, template_from_string, country_timezones
session
Function moves the functionality of the Laravel session()
helper function to Twig.
{{ session('my.session.key') }}
The example would output the value currently stored in my.session.key
.
See more about the Laravel session helper function here.
You can also use OctoberCMS function: {{ this.session.get('my.session.key') }}
, but it's little bit longer :-)
trans
Function moves the functionality of the Laravel trans()
helper function to Twig.
{{ trans('acme.blog::lang.app.name') }}
The example would output a value stored in a localization file of an imaginary blog plugin. See more about localization in October CMS here.
You can also use trans filter: {{ 'acme.blog::lang.app.name'|trans }}
.
var_dump
Dumps information about a variable. Can be also used as a filter.
<pre>{{ var_dump(users) }}</pre>
You can also use {{ dump(users) }} function to dump information about a variable. Properties are "clickable" to expand.
template_from_string
The function loads a template from a string.
{% set name = 'John' %} {{ include(template_from_string("Hello {{ name }}")) }} {{ include(template_from_string("Hurry up it is: {{ "now"|date("m/d/Y") }}")) }}
country_timezones
The country_timezones function returns the names of the timezones associated with a given country code:
{# Europe/Paris #} {{ country_timezones('FR')|join(', ') }}
Available filters
- PHP functions: strftime, ltrim, rtrim, var_dump, wordwrap
- custom functions: revision
- internationalized names filters: country_name, currency_name, currency_symbol, language_name, locale_name, timezone_name
- localized formatters filters: format_currency, format_number, format_*_number, format_datetime, format_date, format_time
strftime
Format a local time/date according to locale settings.
Posted at {{ article.date | strftime('%d.%m.%Y %H:%M:%S') }}
The example would output Posted at 04.01.2016 22:57:42. See more format parameters.
You can also use {{ carbon(article.date).formatLocalized('%d.%m.%Y %H:%M:%S') }}
.
ltrim
Strip whitespace (or other characters) from the beginning of a string.
Hello I'm {{ ' jack' | ltrim }}
The example would output Hello I'm jack without whitespaces from the start.
You can also use {{ ' I like Twig. '|trim(side='left') }}
native Twig filter.
rtrim
Strip whitespace (or other characters) from the end of a string.
Hello I'm {{ 'jack ' | rtrim }}
The example would output Hello I'm jack without whitespaces from the end.
You can also use {{ ' I like Twig. '|trim(side='right') }}
native Twig filter.
var_dump
Dumps information about a variable.
<pre>{{ users | var_dump }}</pre>
You can also use {{ var_dump(users) }}
or {{ dump(users) }}
functions.
wordwrap
Use the wordwrap filter to split your text into lines with equal length.
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing" | wordwrap(10) }}
This example would print:
Lorem ipsu m dolor si t amet, co nsectetur adipiscing
The default separator is "\n", but you can easily change that by providing one:
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing" | wordwrap(10, "zz\n") }}
This would result in:
Lorem ipsuzz m dolor sizz t amet, cozz nsectetur zz adipiscing
revision
Force the browser to reload cached modified/updated asset files. You can provide a format parameter so that the prepended timestamp gets converted accordingly to the PHP date() function.
usage
<img src="{{ 'assets/images/image_file.jpg' | theme | revision("m.d.y.H.i.s") }}" alt="an image" />
Will return something like
<img src="https://www.example.com/themes/my-theme/assets/image_file.png?12.03.16.04.52.38" alt="An image" />
See: https://github.com/vojtasvoboda/oc-twigextensions-plugin/issues/25
https://stackoverflow.com/questions/32414/how-can-i-force-clients-to-refresh-javascript-files
http://php.net/manual/en/function.date.php
country_name
The country_name filter returns the country name given its ISO-3166 two-letter code:
{# France #} {{ 'FR'|country_name }}
By default, the filter uses the current locale. You can pass it explicitly:
{# États-Unis #} {{ 'US'|country_name('fr') }}
currency_name
The currency_name filter returns the currency name given its three-letter code:
{# Euro #} {{ 'EUR'|currency_name }} {# Japanese Yen #} {{ 'JPY'|currency_name }}
By default, the filter uses the current locale. You can pass it explicitly:
{# yen japonais #} {{ 'JPY'|currency_name('fr_FR') }}
currency_symbol
The currency_symbol filter returns the currency symbol given its three-letter code:
{# € #} {{ 'EUR'|currency_symbol }} {# ¥ #} {{ 'JPY'|currency_symbol }}
By default, the filter uses the current locale. You can pass it explicitly:
{# ¥ #} {{ 'JPY'|currency_symbol('fr') }}
language_name
The language_name filter returns the language name given its two-letter code:
{# German #} {{ 'de'|language_name }}
By default, the filter uses the current locale. You can pass it explicitly:
{# allemand #} {{ 'de'|language_name('fr') }} {# français canadien #} {{ 'fr_CA'|language_name('fr_FR') }}
locale_name
The locale_name filter returns the locale name given its two-letter code:
{# German #} {{ 'de'|locale_name }}
By default, the filter uses the current locale. You can pass it explicitly:
{# allemand #} {{ 'de'|locale_name('fr') }} {# français (Canada) #} {{ 'fr_CA'|locale_name('fr_FR') }}
timezone_name
The timezone_name filter returns the timezone name given a timezone identifier:
{# Central European Time (Paris) #} {{ 'Europe/Paris'|timezone_name }} {# Pacific Time (Los Angeles) #} {{ 'America/Los_Angeles'|timezone_name }}
By default, the filter uses the current locale. You can pass it explicitly:
{# heure du Pacifique nord-américain (Los Angeles) #} {{ 'America/Los_Angeles'|timezone_name('fr') }}
format_currency
The format_currency filter formats a number as a currency:
{# €1,000,000.00 #} {{ '1000000'|format_currency('EUR') }}
You can pass attributes to tweak the output:
{# €12.34 #} {{ '12.345'|format_currency('EUR', {rounding_mode: 'floor'}) }} {# €1,000,000.0000 #} {{ '1000000'|format_currency('EUR', {fraction_digit: 4}) }}
The list of supported options:
- grouping_used;
- decimal_always_shown;
- max_integer_digit;
- min_integer_digit;
- integer_digit;
- max_fraction_digit;
- min_fraction_digit;
- fraction_digit;
- multiplier;
- grouping_size;
- rounding_mode;
- rounding_increment;
- format_width;
- padding_position;
- secondary_grouping_size;
- significant_digits_used;
- min_significant_digits_used;
- max_significant_digits_used;
- lenient_parse.
By default, the filter uses the current locale. You can pass it explicitly:
{# 1.000.000,00 € #} {{ '1000000'|format_currency('EUR', locale='de') }}
format_number and format_*_number
The format_number filter formats a number:
{{ '12.345'|format_number }}
You can pass attributes to tweak the output:
{# 12.34 #} {{ '12.345'|formaty_number({roundingy_mode: 'floor'}) }} {# 1000000.0000 #} {{ '1000000'|formaty_number({fractiony_digit: 4}) }}
The list of supported options:
- grouping_used;
- decimal_always_shown;
- max_integer_digit;
- min_integer_digit;
- integer_digit;
- max_fraction_digit;
- min_fraction_digit;
- fraction_digit;
- multiplier;
- grouping_size;
- rounding_mode;
- rounding_increment;
- format_width;
- padding_position;
- secondary_grouping_size;
- significant_digits_used;
- min_significant_digits_used;
- max_significant_digits_used;
- lenient_parse.
Besides plain numbers, the filter can also format numbers in various styles:
{# 1,234% #} {{ '12.345'|format_number(style='percent') }} {# twelve point three four five #} {{ '12.345'|format_number(style='spellout') }} {# 12 sec. #} {{ '12'|format_duration_number }}
The list of supported styles:
- decimal;
- currency;
- percent;
- scientific;
- spellout;
- ordinal;
- duration.
As a shortcut, you can use the format_*_number filters by replacing *
with a style:
{# 1,234% #} {{ '12.345'|format_percent_number }} {# twelve point three four five #} {{ '12.345'|format_spellout_number }}
You can pass attributes to tweak the output:
{# 12.3% #} {{ '0.12345'|format_percent_number({rounding_mode: 'floor', fraction_digit: 1}) }}
By default, the filter uses the current locale. You can pass it explicitly:
{# 12,345 #} {{ '12.345'|format_number(locale='fr') }}
format_datetime
The format_datetime filter formats a date time:
{# Aug 7, 2019, 11:39:12 PM #} {{ '2019-08-07 23:39:12'|format_datetime() }}
Format
You can tweak the output for the date part and the time part:
{# 23:39 #} {{ '2019-08-07 23:39:12'|format_datetime('none', 'short', locale='fr') }} {# 07/08/2019 #} {{ '2019-08-07 23:39:12'|format_datetime('short', 'none', locale='fr') }} {# mercredi 7 août 2019 23:39:12 UTC #} {{ '2019-08-07 23:39:12'|format_datetime('full', 'full', locale='fr') }}
Supported values are: none, short, medium, long, and full.
For greater flexibility, you can even define your own pattern (see the ICU user guide for supported patterns).
{# 11 oclock PM, GMT #} {{ '2019-08-07 23:39:12'|format_datetime(pattern="hh 'oclock' a, zzzz") }}
Locale
By default, the filter uses the current locale. You can pass it explicitly:
{# 7 août 2019 23:39:12 #} {{ '2019-08-07 23:39:12'|format_datetime(locale='fr') }}
Timezone
By default, the date is displayed by applying the default timezone (the one specified in php.ini or declared in Twig -- see below), but you can override it by explicitly specifying a timezone:
{{ datetime|format_datetime(locale='en', timezone='Pacific/Midway') }}
If the date is already a DateTime object, and if you want to keep its current timezone, pass false as the timezone value:
{{ datetime|format_datetime(locale='en', timezone=false) }}
The default timezone can also be set globally by calling setTimezone():
$twig = new \Twig\Environment($loader); $twig->getExtension(\Twig\Extension\CoreExtension::class)->setTimezone('Europe/Paris');
format_date
The format_date filter formats a date. It behaves in the exact same way as the format_datetime filter, but without the time.
format_time
The format_time filter formats a time. It behaves in the exact same way as the format_datetime filter, but without the date.
Version 1 for October 1.0.x, 1.1.x, 2.0.x
Features
- supported filters strftime, uppercase, lowercase, ucfirst, lcfirst, ltrim, rtrim, str_repeat, plural, truncate, wordwrap, strpad, leftpad, rightpad, rtl, shuffle, time_diff, localizeddate, localizednumber, localizedcurrency, mailto, var_dump, revision, sortbyfield
- supported functions config, session, trans, var_dump, template_from_string
- special filter mailto for rendering encrypted email as spam prevention
Available filters
strftime, uppercase, lowercase, ucfirst, lcfirst, ltrim, rtrim, str_repeat, plural, truncate, wordwrap, strpad, leftpad, rightpad, rtl, shuffle, time_diff, localizeddate, localizednumber, localizedcurrency, mailto, var_dump, revision, sortbyfield
strftime
Format a local time/date according to locale settings.
Posted at {{ article.date | strftime('%d.%m.%Y %H:%M:%S') }}
The example would output Posted at 04.01.2016 22:57:42. See more format parameters.
uppercase
Make a string uppercase
Hello I'm {{ 'Jack' | uppercase }}
The example would output Hello I'm JACK.
lowercase
Make a string lowercase
Hello I'm {{ 'JACK' | lowercase }}
The example would output Hello I'm jack.
ucfirst
Make a string's first character uppercase
Hello I'm {{ 'jack' | ucfirst }}
The example would output Hello I'm Jack.
lcfirst
Make a string's first character lowercase
Hello I'm {{ 'Jack' | lcfirst }}
The example would output Hello I'm jack.
ltrim
Strip whitespace (or other characters) from the beginning of a string
Hello I'm {{ ' jack' | ltrim }}
The example would output Hello I'm jack without whitespaces from the start.
rtrim
Strip whitespace (or other characters) from the end of a string.
Hello I'm {{ 'jack ' | rtrim }}
The example would output Hello I'm jack without whitespaces from the end.
str_repeat
Repeat a string
I'm the {{ 'best' | str_repeat(3) }}!
The example would output I'm the best best best!
plural
Get the plural form of an English word.
You have {{ count }} new {{ 'mail' | plural(count) }}
The example would output You have 1 new mail or You have 3 new mails - depending on mails count.
truncate
Use the truncate filter to cut off a string after limit is reached
{{ "Hello World!" | truncate(5) }}
The example would output Hello..., as ... is the default separator.
You can also tell truncate to preserve whole words by setting the second parameter to true. If the last Word is on the the separator, truncate will print out the whole Word.
{{ "Hello World!" | truncate(7, true) }}
Here Hello World! would be printed.
If you want to change the separator, just set the third parameter to your desired separator.
{{ "Hello World!" | truncate(7, false, "??") }}
This example would print Hello W??.
wordwrap
Use the wordwrap filter to split your text in lines with equal length.
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing" | wordwrap(10) }}
This example would print:
Lorem ipsu m dolor si t amet, co nsectetur adipiscing
The default separator is "\n", but you can easily change that by providing one:
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing" | wordwrap(10, "zz\n") }}
This would result in:
Lorem ipsuzz m dolor sizz t amet, cozz nsectetur zz adipiscing
rtl
Reverse a string.
{{ 'Hello world!' | rtl }}
This would print:
!dlrow olleH
shuffle
Shuffle an array
{{ songs | shuffle }}
time_diff
Use the time_diff filter to render the difference between a date and now.
{{ post.published_at | time_diff }}
The example above will output a string like 4 seconds ago or in 1 month, depending on the filtered date.
time_diff arguments
- date: The date for calculate the difference from now. Can be a string or a DateTime instance.
- now: The date that should be used as now. Can be a string or a DateTime instance. Do not set this argument to use current date.
time_diff translation
To get a translatable output, give a Symfony\Component\Translation\TranslatorInterface as constructor argument. The returned string is formatted as diff.ago.XXX or diff.in.XXX where XXX can be any valid unit: second, minute, hour, day, month, year.
localizeddate
Use the localizeddate filter to format dates into a localized string representating the date.
{{ post.published_at | localizeddate('medium', 'none', locale) }}
The localizeddate filter accepts strings (it must be in a format supported by the strtotime function), DateTime instances, or Unix timestamps.
localizeddate arguments
- date_format: The date format. Choose one of these formats:
- 'none': IntlDateFormatter::NONE
- 'short': IntlDateFormatter::SHORT
- 'medium': IntlDateFormatter::MEDIUM
- 'long': IntlDateFormatter::LONG
- 'full': IntlDateFormatter::FULL
- time_format: The time format. Same formats possible as above.
- locale: The locale used for the format. If NULL is given, Twig will use Locale::getDefault()
- timezone: The date timezone
- format: Optional pattern to use when formatting or parsing. Possible patterns are documented in the ICU user guide.
localizednumber
Use the localizednumber filter to format numbers into a localized string representating the number.
{{ product.quantity | localizednumber }}
Internally, Twig uses the PHP NumberFormatter::create() function for the number.
localizednumber arguments
- style: Optional date format (default: 'decimal'). Choose one of these formats:
- 'decimal': NumberFormatter::DECIMAL
- 'currency': NumberFormatter::CURRENCY
- 'percent': NumberFormatter::PERCENT
- 'scientific': NumberFormatter::SCIENTIFIC
- 'spellout': NumberFormatter::SPELLOUT
- 'ordinal': NumberFormatter::ORDINAL
- 'duration': NumberFormatter::DURATION
- type: Optional formatting type to use (default: 'default'). Choose one of these types:
- 'default': NumberFormatter::TYPE_DEFAULT
- 'int32': NumberFormatter::TYPE_INT32
- 'int64': NumberFormatter::TYPE_INT64
- 'double': NumberFormatter::TYPE_DOUBLE
- 'currency': NumberFormatter::TYPE_CURRENCY
- locale: The locale used for the format. If NULL is given, Twig will use Locale::getDefault()
localizedcurrency
Use the localizedcurrency filter to format a currency value into a localized string.
{{ product.price | localizedcurrency('EUR') }}
localizedcurrency arguments
- currency: The 3-letter ISO 4217 currency code indicating the currency to use.
- locale: The locale used for the format. If NULL is given, Twig will use Locale::getDefault()
mailto
Filter for rendering email as normal mailto link, but with encryption against bots!
{{ 'vojtasvoboda.cz@gmail.com' | mailto }}
returns
<span id="e846043876">[javascript protected email address]</span><script type="text/javascript">/*<![CDATA[*/eval("var a=\"9IV1G0on6.ryWZYS28iPcNBwq4aeUJF5CskjuLQAh3XdlEz@7KtmpHbTxM-ODg_+Rvf\";var b=a.split(\"\").sort().join(\"\");var c=\"_TtD3O_TXTl3VdfZ@H3KpVdTH\";var d=\"\";for(var e=0;e<c.length;e++)d+=b.charAt(a.indexOf(c.charAt(e)));document.getElementById(\"e846043876\").innerHTML=\"<a href=\\\"mailto:\"+d+\"\\\">\"+d+\"</a>\"")/*]]>*/</script>
which will be rendered to page as normal
<a href="mailto:vojtasvoboda.cz@gmail.com">vojtasvoboda.cz@gmail.com</a>
PHP encrypts your email address and generates the JavaScript that decrypts it. Most bots can't execute JavaScript and that is what makes this work. A visitors of your web page will not notice that you used this script as long as they has JavaScript enabled. The visitors will see "[javascript protected email address]" instead of the email address if they has JavaScript disabled.
You can also use additional filter parameters
{{ 'vojtasvoboda.cz@gmail.com' | mailto(true, true, 'Let me know', 'my-class') }}
Where first parameter means "returns email with mailto link" and you can set it to false. Second parameter means "encryption is enabled". Third is link text and fourth is custom CSS class.
var_dump
Dumps information about a variable.
<pre>{{ users | var_dump }}</pre>
revision
Force the browser to reload cached modified/updated asset files. You can provide a format parameter so that the prepended timestamp get converted accordingly to the PHP date() function.
<img src="{{ 'assets/images/image_file.jpg' | theme | revision("m.d.y.H.i.s") }}" />
Will return something like
<img src="https://www.example.com/themes/my-theme/assets/image_file.png?12.03.16.04.52.38" />
sortbyfield
Sort array/collection by given field (key).
{% set data = [{'name': 'David', 'age': 31}, {'name': 'John', 'age': 28}] %} {% for item in data | sortbyfield('age') %} {{ item.name }} {% endfor %}
Output will be: John David
Available functions
config, session, trans, var_dump, template_from_string
config
Function transports the functionality of the Laravel config()
helper function to Twig.
{{ config('app.locale') }}
The example would output the value currently stored in app.locale
.
See more about the Laravel config helper function here.
session
Function transports the functionality of the Laravel session()
helper function to Twig.
{{ session('my.session.key') }}
The example would output the value currently stored in my.session.key
.
See more about the Laravel session helper function here.
trans
Function transports the functionality of the Laravel trans()
helper function to Twig.
{{ trans('acme.blog::lang.app.name') }}
The example would output a value stored in a localization file of an imaginary blog plugin. See more about localization in October CMS here.
var_dump
Dumps information about a variable. Can be also used as a filter.
<pre>{{ var_dump(users) }}</pre>
template_from_string
Function loads a template from a string.
{% set name = 'John' %} {{ include(template_from_string("Hello {{ name }}")) }} {{ include(template_from_string("Hurry up it is: {{ "now"|date("m/d/Y") }}")) }}
The following plugins extend or depend on the plugin
Job applications management
Simple and powerful plugin to setup job listings on your website
Job applications management
Simple and powerful plugin to setup job listings on your website
Member Bill
Membership / Package Sales System
Member Bill
Membership / Package Sales System
SEO Manager Pro
SEO, Sitemap, Robots and Open Graph for CMS Pages, Static Pages, Blog Posts
SEO Manager Pro
SEO, Sitemap, Robots and Open Graph for CMS Pages, Static Pages, Blog Posts
SEO Manager Light
SEO, Sitemap and Robots for CMS Pages, Static Pages and Blog Posts
SEO Manager Light
SEO, Sitemap and Robots for CMS Pages, Static Pages and Blog Posts
Soldlots
Catalog of sold cars on auctions
Soldlots
Catalog of sold cars on auctions
The following themes use this plugin
Sneakers E-Commerce Theme for Shopaholic
Sneakers E-Commerce Theme for Shopaholic
Customizable and mobile-friendly e-commerce theme for Shopaholic designed especially for an online shoe store.
Vermillion
Vermillion
Ultimate Responsive Company Profile Theme
Yell-Ow!
Yell-Ow!
Yell-Ow! - Ultimate Company Profile
Axiam E-Commerce Theme for Shopaholic
Axiam E-Commerce Theme for Shopaholic
Responsive Bootstrap 4 Shopaholic theme for October CMS
Biolia E-Commerce Theme for Shopaholic
Biolia E-Commerce Theme for Shopaholic
Customizable and mobile-friendly e-commerce theme for Shopaholic designed especially for an online organic food & eco products store.
Levo
Levo
Theme specially designed for tutoring/teaching bussines
AdminLTE24Pro
AdminLTE24Pro
AdminLTEPro is a fully responsive administration template. Highly customizable and easy to use.
Installation
Just install VojtaSvoboda.TwigExtensions plugin a you can use new added plugin at your templates:
<h1 class="heading">{{ article.heading | uppercase }}</h1> <p class="created"> Posted at {{ article.date | strftime('%d.%m.%Y %H:%M:%S') }} </p> <p class="perex"> {{ article.perex | truncate(80) }} </p>
Contributing
Do you want some extra feature or fix bug? Send me pull request or create issue, please.
Code check
Unit tests
License
Twig extensions plugin is open-sourced software licensed under the MIT license same as OctoberCMS platform.
Icon made by Freepik from www.flaticon.com.
-
Bruce Wayne
Found the plugin useful on 30 Nov, 2022
I found a bug five hours ago, now it's fixed. WOW!
The plugin delivers very handy functionalities and I use it in almost every project.
Thanks Vojta Svoboda
-
Ostlancer FZE LLC
Found the plugin useful on 10 Jul, 2021
Thanks a lot, Vojta!
-
Noly Bom
Found the plugin useful on 2 Sep, 2020
A must plugin! Thank you!!!
-
Paulo Cesar Soto
Found the plugin useful on 20 Jun, 2020
This plugin help me to validate if the image exists on disk, I add the PHP function on his section getPhpFunctions.
Great Plugin!!
-
Daniels Teddy
Found the plugin useful on 23 Feb, 2020
Alway in my plugins handbook, thank you for your great work!
-
Jean Perez
Found the plugin useful on 26 Jul, 2019
Great plugin
-
Lovata sp. z o.o.
Found the plugin useful on 15 Mar, 2019
Thx for the great plugin!
We're using it in each of our projects based on October CMS to work with Twig templates in a more comfortable way.
-
Jan Vince
Found the plugin useful on 25 Oct, 2018
Great work! One of my essential plugins.
-
Szabó Gergő
Found the plugin useful on 7 Aug, 2018
Very useful and essential plugin. Thank you!
-
Abdulsalam
Found the plugin useful on 22 Mar, 2018
Thanks for the plugin! How to make in Russian?
-
Vojta Svoboda author
Replied on 23 Mar, 2018
Just create pull request in official repository, it's easy :-) https://github.com/vojtasvoboda/oc-twigextensions-plugin
-
Justin Patterson
Found the plugin useful on 6 Feb, 2018
I was so happy when I found this plugin. I didn't even know how much I needed some of these filters, now I use them so much. Cheers!
-
papaya
Found the plugin useful on 17 Jan, 2018
Great work!
-
Akkarin
Found the plugin useful on 18 Jan, 2017
Very usefull plugin! Thank you very much!
-
Ronaldo Ribeiro de Sousa
Found the plugin useful on 9 Jan, 2017
Great work!
Excellent plugin
Thanks Vojta Svoboda
-
Zanor
Found the plugin useful on 28 Nov, 2016
Excellent plugin, provides some very useful filters which saves me a lot of time.
Vojta, thanks for the new mailto filter, I'm loving it! :)
-
Arman Zhilkaidarov
Found the plugin useful on 12 Aug, 2016
Great works!
Add please this extension) https://github.com/asm89/twig-cache-extension
-
sam
Found the plugin useful on 4 Jul, 2016
good work
-
Sebastian Hilger
Found the plugin useful on 18 Apr, 2016
Great plugin, very useful.
-
2.0.5 |
Fix checking if Intl is installed May 13, 2024 |
---|---|
2.0.4 |
Fix loading intl filters requires Twig environment May 09, 2024 |
2.0.3 |
Fix for PHP without intl extension Nov 30, 2022 |
2.0.2 |
Fix compatibility with October 3.0 Nov 29, 2022 |
2.0.1 |
Minor fixes and update documentation Oct 28, 2022 |
2.0.0 |
New version for October 3.1+ Oct 27, 2022 |
1.3.1 |
Fix compatibility with October 2.2.27 on PHP 8 May 31, 2022 |
1.3 |
Fix compatibility with October 2.2.27 May 27, 2022 |
1.2.7 |
Add slovenian locale, thanks to Marko Kodrič Oct 04, 2020 |
1.2.6 |
Fix ucfirst, thanks to Aurélien Roy Jan 24, 2020 |
1.2.5 |
Add env() helper function, thanks to Marek Závacký Mar 22, 2019 |
1.2.4 |
Add sk_SK locale, thanks to Marek Závacký Feb 22, 2019 |
1.2.3 |
Added an optional css class parameter to mailto function Oct 20, 2018 |
1.2.2 |
Add str_replace filter (thanks to Szabó Gergő) May 10, 2018 |
1.2.1 |
Add linter and code sniffer for better automatization. Feb 04, 2018 |
1.2.0 |
Require PHP 7.0 as minimum version. Sep 24, 2017 |
1.1.3 |
Add sortbyfield filter to sorting arrays/fields by key. Sep 11, 2017 |
1.1.2 |
Add strip_tags filter Sep 11, 2017 |
1.1.1 |
Add revision filter Aug 03, 2017 |
1.1.0 |
Make changes for Laravel 5.5. Aug 03, 2017 |
1.0.15 |
Add DE and HU locale (thanks to Szabó Gergő and Sebastian Hilger) Jan 09, 2017 |
1.0.14 |
Add pt-br locale for time_diff translation (thanks to Ronaldo Ribeiro de Sousa) Jan 08, 2017 |
1.0.13 |
Make time_diff translatable. Jan 08, 2017 |
1.0.12 |
Add mailto text parameter and rtl filter. Dec 20, 2016 |
1.0.11 |
Add mailto filter for rendering encrypted email addresses. Nov 28, 2016 |
1.0.10 |
Remove pre tag from var_dump Oct 15, 2016 |
1.0.9 |
Add var_dump filter and function. Oct 15, 2016 |
1.0.8 |
Plugin can be installed over Composer. Oct 15, 2016 |
1.0.7 |
Add the session() and trans() helper functions (thanks to Sebastian Hilger) Jul 12, 2016 |
1.0.6 |
Fix localizednumber and localizedcurrency filters (thanks to Vita Zoubek) Apr 20, 2016 |
1.0.5 |
Add config function (thanks to Sebastian Hilger) Apr 18, 2016 |
1.0.4 |
Add leftpad, rightpad and strpad filters. Cover by unit tests. Mar 25, 2016 |
1.0.3 |
Fix uppercase, lowercase and ucfirst for UTF-8 characters Mar 07, 2016 |
1.0.2 |
Add template_from_string function Feb 28, 2016 |
1.0.1 |
First version of TwigExtensions Jan 05, 2016 |
Upgrading to October CMS v3.1
This guide can be used to help migrate from VojtaSvoboda.TwigExtensions
. It involves replacing some Twig functions with the native syntax.
Beginning from October CMS v3.1.17, some new functions were added to the core that replaced some functions provided by this plugin, and many of the functions were already available in the core. Use the following document to find the latest syntax for each extension function.
Updated Functions
config
The {{ config(...) }}
Twig function is native in October v3.1.17+
env
The {{ env(...) }}
Twig function is native in October v3.1.17+
session
You can still use {{ session('my.session.key') }}
or use native October v3.1.17+ function:
{{ this.session.get('my.session.key') }}
to access session variables.
trans
You can still use function {{ trans('acme.blog::lang.app.name') }}
or use native October v3.1.17+ filter:
{{ 'acme.blog::lang.app.name'|trans }}
to access translations.
var_dump
You can still use function {{ var_dump(users) }}
or filter {{ users | var_dump }}
or use native October v3.1.17+ function:
{{ dump(users) }}
to dump information about a variable. Properties are "clickable" to expand.
strftime
You can still use filter {{ article.date | strftime('%d.%m.%Y %H:%M:%S') }}
or use the carbon()
function to build a carbon object, combined with formatLocalized
, available in October v3.1.17+
{{ carbon(article.date).formatLocalized('%d.%m.%Y %H:%M:%S') }}
Updated Filters
uppercase
Use the str_upper
filter or just upper
:
{{ 'Jack'|str_upper }}
lowercase
Use the str_lower
filter or just lower
:
{{ 'JACK'|str_lower }}
ucfirst
Use the str_ucfirst
filter
{{ 'jack'|str_ucfirst }}
lcfirst
Use the str_lcfirst
filter
{{ 'Jack'|str_lcfirst }}
ltrim
You can still use function {{ ' jack' | ltrim }}
or use the native trim
Twig filter: https://twig.symfony.com/doc/2.x/filters/trim.html
rtrim
You can still use function {{ ' jack' | rtrim }}
or use the native trim
Twig filter: https://twig.symfony.com/doc/2.x/filters/trim.html
str_repeat
Use the str_repeat
filter
I'm the {{ 'best '|str_repeat(3) }}!
plural
Use the str_plural
filter
You have {{ count }} new {{ 'mail'|str_plural(count) }}
truncate
Use the str_limit
filter
{{ "Hello World!"|str_limit(5) }} {{ "Hello World!"|str_limit(5, '...') }}
strpad
Use the str_pad_both
filter
{{ 'xxx'|str_pad_both(7, 'o') }}
str_replace
Use the str_replace
filter
{{ 'Alice'|str_replace('Alice', 'Bob') }}
strip_tags
You can still use function {{ '<p><b>Text</b></p>' | strip_tags('<p>') }}
or use the html_strip
October filter
{{ '<p><b>Text</b></p>'|html_strip }}
leftpad
Use the str_pad_left
filter
{{ 'xxx'|str_pad_left(5, 'o') }}
rightpad
Use the str_pad_right
filter
{{ 'xxx'|str_pad_right(5, 'o') }}
rtl
Use the str_reverse
filter
{{ 'Hello world!'|str_reverse }}
shuffle
Use the collect
function with shuffle
method
{{ collect(songs).shuffle() }}
time_diff
Use the carbon()
function with diffForHumans
{{ carbon(post.published_at).diffForHumans() }}
localizeddate
Use {{ post.published_at | format_date('medium') }}
instead.
See https://twig.symfony.com/doc/3.x/filters/format_date.html
localizednumber
Use {{ 42.42 | format_number }}
instead.
See https://twig.symfony.com/doc/3.x/filters/format_number.html
localizedcurrency
Use {{ '1000000' | format_currency('EUR') }}
instead.
See https://twig.symfony.com/doc/3.x/filters/format_currency.html
mailto
Use the html_mailto
filter
{{ 'octobercms@gmail.tld'|html_mailto }}
var_dump
You can use var_dump filter or use the dump()
native OctoberCMS function
{{ dump(users) }}
sortbyfield
Use collect()
with sort
collect(data).sortBy('age') collect(data).sortByDesc('age')
For example:
{% set data = [{'name': 'David', 'age': 31}, {'name': 'John', 'age': 28}] %} {% for item in collect(data).sortBy('age') %} {{ item.name }} {% endfor %}