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.
The {{ config(...) }}
Twig function is native in October v3.1.17+
The {{ env(...) }}
Twig function is native in October v3.1.17+
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.
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.
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.
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') }}
Use the str_upper
filter or just upper
:
{{ 'Jack'|str_upper }}
Use the str_lower
filter or just lower
:
{{ 'JACK'|str_lower }}
Use the str_ucfirst
filter
{{ 'jack'|str_ucfirst }}
Use the str_lcfirst
filter
{{ 'Jack'|str_lcfirst }}
You can still use function {{ ' jack' | ltrim }}
or use the native trim
Twig filter: https://twig.symfony.com/doc/2.x/filters/trim.html
You can still use function {{ ' jack' | rtrim }}
or use the native trim
Twig filter: https://twig.symfony.com/doc/2.x/filters/trim.html
Use the str_repeat
filter
I'm the {{ 'best '|str_repeat(3) }}!
Use the str_plural
filter
You have {{ count }} new {{ 'mail'|str_plural(count) }}
Use the str_limit
filter
{{ "Hello World!"|str_limit(5) }}
{{ "Hello World!"|str_limit(5, '...') }}
Use the str_pad_both
filter
{{ 'xxx'|str_pad_both(7, 'o') }}
Use the str_replace
filter
{{ 'Alice'|str_replace('Alice', 'Bob') }}
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 }}
Use the str_pad_left
filter
{{ 'xxx'|str_pad_left(5, 'o') }}
Use the str_pad_right
filter
{{ 'xxx'|str_pad_right(5, 'o') }}
Use the str_reverse
filter
{{ 'Hello world!'|str_reverse }}
Use the collect
function with shuffle
method
{{ collect(songs).shuffle() }}
Use the carbon()
function with diffForHumans
{{ carbon(post.published_at).diffForHumans() }}
Use {{ post.published_at | format_date('medium') }}
instead.
See https://twig.symfony.com/doc/3.x/filters/format_date.html
Use {{ 42.42 | format_number }}
instead.
See https://twig.symfony.com/doc/3.x/filters/format_number.html
Use {{ '1000000' | format_currency('EUR') }}
instead.
See https://twig.symfony.com/doc/3.x/filters/format_currency.html
Use the html_mailto
filter
{{ 'octobercms@gmail.tld'|html_mailto }}
You can use var_dump filter or use the dump()
native OctoberCMS function
{{ dump(users) }}
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 %}