Download the PHP package vojtasvoboda/oc-twigextensions-plugin without Composer
On this page you can find all versions of the php package vojtasvoboda/oc-twigextensions-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vojtasvoboda/oc-twigextensions-plugin
More information about vojtasvoboda/oc-twigextensions-plugin
Files in vojtasvoboda/oc-twigextensions-plugin
Package oc-twigextensions-plugin
Short Description Register more Twig filters for your OctoberCMS templates
License MIT
Informations about the package oc-twigextensions-plugin
Twig extensions
Twig extensions plugin for OctoberCMS adds new filter and functions to your templates. No other plugin dependencies. Tested with the latest stable OctoberCMS 3.1.18 on PHP 8.0.
Versions
There are two versions of this plugin - 1.x and 2.x. For older October 1.0.x, 1.1.x or 2.x.x use special branch 1.x. For October 3.1+ use master branch.
For old Laravel 5.4 October's versions use special branch laravel54
.
For migrating between plugin's version 1 and version 2 you can use special UPGRADE.md guide.
Installation
Install plugin from CMS backend or by Composer:
Than you can use newly added filters/functions at your templates:
Available functions
session, trans, var_dump, template_from_string, country_timezones
session
Function moves the functionality of the Laravel session()
helper function to Twig.
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.
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.
You can also use {{ dump(users) }} function to dump information about a variable. Properties are "clickable" to expand.
template_from_string
Function loads a template from a string.
country_timezones
The country_timezones function returns the names of the timezones associated with a given country code:
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, formatnumber, format*_number, format_datetime, format_date, format_time
strftime
Format a local time/date according to locale settings.
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.
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.
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.
You can also use <pre>{{ var_dump(users) }}</pre>
or {{ dump(users) }}
functions.
wordwrap
Use the wordwrap filter to split your text into lines with equal length.
This example would print:
The default separator is "\n", but you can easily change that by providing one:
This would result in:
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
Will return something like
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:
By default, the filter uses the current locale. You can pass it explicitly:
currency_name
The currency_name filter returns the currency name given its three-letter code:
By default, the filter uses the current locale. You can pass it explicitly:
currency_symbol
The currency_symbol filter returns the currency symbol given its three-letter code:
By default, the filter uses the current locale. You can pass it explicitly:
language_name
The language_name filter returns the language name given its two-letter code:
By default, the filter uses the current locale. You can pass it explicitly:
locale_name
The locale_name filter returns the locale name given its two-letter code:
By default, the filter uses the current locale. You can pass it explicitly:
timezone_name
The timezone_name filter returns the timezone name given a timezone identifier:
By default, the filter uses the current locale. You can pass it explicitly:
format_currency
The format_currency filter formats a number as a currency:
You can pass attributes to tweak the output:
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:
formatnumber and format*_number
The format_number filter formats a number:
You can pass attributes to tweak the output:
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:
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:
You can pass attributes to tweak the output:
By default, the filter uses the current locale. You can pass it explicitly:
format_datetime
The format_datetime filter formats a date time:
Format
You can tweak the output for the date part and the time part:
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).
Locale
By default, the filter uses the current locale. You can pass it explicitly:
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:
If the date is already a DateTime object, and if you want to keep its current timezone, pass false as the timezone value:
The default timezone can also be set globally by calling setTimezone():
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.
Removed functions
Functions used in plugin's version 1.x for October 1.0.x, 1.1.x, 2.0.x and removed from this version:
- config() - it's native function since October 3.1.17
- env() - it's native function since October 3.1.17
Removed filters
Filters used in plugin's version 1.x for October 1.0.x, 1.1.x, 2.0.x and removed from this version:
- uppercase - use str_upper or just upper
- lowercase - use str_lower or just lower
- ucfirst - use str_ucfirst
- lcfirst - use str_lcfirst
- str_repeat - it's native filter now
- plural - use str_plural
- truncate - use str_limit
- strpad - use str_pad_both
- str_replace - it's native filter now
- strip_tags - use html_strip
- leftpad - use str_pad_left
- rightpad - use str_pad_right
- rtl - use str_reverse
- shuffle - use
collect(songs).shuffle()
- time_diff - use
carbon(post.published_at).diffForHumans()
- localizeddate - use format_date
- localizednumber - use format_number
- localizedcurrency - use format_currency
- mailto - use html_mailto
- var_dump - use dump function
- sortbyfield - use
collect(data).sortBy('age')
orcollect(data).sortByDesc('age')
For more info see UPGRADE.md guide.
Contributing
- [ ] Make template_from_string turned off by default and add special checkbox to the backend to allow it.
- [ ] Add missing unit tests.
- [ ] New filters ga and gtm for adding GA or GTM code (Heap Analytics) - {{ 'UA-1234567' | ga }}.
- [ ] Add cache extension.
Feel free to send pullrequest! Please, send Pull Request to master branch.
License
Twig extensions plugin is open-sourced software licensed under the MIT license same as OctoberCMS platform.
All versions of oc-twigextensions-plugin with dependencies
october/rain Version ^3.0
composer/installers Version ~1.0
twig/intl-extra Version ^3.4