Closed daftspunk closed 2 years ago
As a side note, a new plugin (or this one) could be used to introduce the twig/intl-extra
composer package (described above) and register its extension. That would be pretty cool.
To retrofit this one:
1.x
for the current code, you can continue to maintain 1.x tags from this branchoctober/rain
at >=3.1
like we have done with the translate pluginv2.0.0
)I hope this helps!
Thank @daftspunk for your help! I started to work on a new version/branch and have a few questions/notes (tested on OctoberCMS 3.1.17):
a) {{ "October CMS" | str_replace('CMS', 'ERP') }}
returns ERP, not October ERP... looks like it works only like that: `{{ str_replace('CMS', 'ERP', 'October CMS') }}
b) arr_shuffle
not works, nor the array_shuffle
, nor the shuffle
... it throws a "not existing filter" exception
c) {{ 'octobercms@gmail.tld'|html_mailto|raw }} requires raw
on the end, otherwise returns just HTML encoded version
Thanks, @vojtasvoboda!
a) This is a bug, fixed in v3.1.18
b) Oops, I thought, arr_*
proxied to \Arr::*
. We should be using collect().shuffle()
here anyway. Docs have been updated:
{{ collect(songs).shuffle() }}
c) Another bug, fixed in v3.1.18
One more thing @daftspunk maybe related to html_mailto issue above:
{{ '<p><strong>Test</strong></p>'|html_strip('<p>')|raw }}
When using html_strip with specify allow tags, I have to use raw filter, otherwise, it renders HTML entities.
I've prepared and tested twig/intl-extra
integration and the new plugin's version is almost done! :-) Just polishing readme etc.
Ok, we can fix this in the next patch. It looks like all html_
functions and filters should not be escaped. It should be fixed in 3.1.19
Great work on the release!
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 available in v3.1.17+env
The
{{ env(...) }}
Twig function is available in v3.1.17+session
Use
{{ this.session.get('my.session.key') }}
to access session variables.trans
Use
{{ 'acme.blog::lang.app.name'|trans }}
filter to access translations.var_dump
Use
{{ dump(users) }}
function to dump information about a variable. Properties are "clickable" to expand.template_from_string
This function is not supported natively for security reasons. You may add this using a new event in v3.1.17+
Alternatively, you can register it in your layout code:
Now the following code will work:
strftime
Use the
carbon()
function to build a carbon object, combined withformatLocalized
, available in v3.1.17+Updated Filters
uppercase
Use the
str_upper
filterlowercase
Use the
str_lower
filterucfirst
Use the
str_ucfirst
filterlcfirst
Use the
str_lcfirst
filterltrim
Use the native
trim
Twig filter: https://twig.symfony.com/doc/2.x/filters/trim.htmlrtrim
Use the native
trim
Twig filter: https://twig.symfony.com/doc/2.x/filters/trim.htmlstr_repeat
Use the
str_repeat
filterplural
Use the
str_plural
filtertruncate
Use the
str_limit
filterwordwrap
This is not available.
strpad
Use the
str_pad_both
filterstr_replace
Use the
str_replace
filterstrip_tags
Use the
html_strip
filterleftpad
Use the
str_pad_left
filterrightpad
Use the
str_pad_right
filterrtl
Use the
str_reverse
filtershuffle
Use the
collect
function withshuffle
methodtime_diff
Use the
carbon()
function withdiffForHumans
localizednumber
Install
twig/intl-extra
packageRegister with Twig, add to
boot()
method in app/Provider.php file.Use the native
format_number
Twig filter: https://twig.symfony.com/doc/3.x/filters/format_number.htmllocalizedcurrency
Follow instructions in localizednumber
Use the native
format_currency
Twig filter: https://twig.symfony.com/doc/3.x/filters/format_currency.htmlmailto
Use the
html_mailto
filtervar_dump
Use the
dump()
functionrevision
Use
carbon()
withformat
Then build the URL like so
sortbyfield
Use
collect()
withsort
For example: