Git Product home page Git Product logo

oc-twigextensions-plugin's Introduction

Twig extensions

Build Status Codacy Scrutinizer Coverage License

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:

composer require vojtasvoboda/oc-twigextensions-plugin

Than you can use newly added filters/functions at your templates:

<h1 class="heading">{{ article.heading | ltrim }}</h1>
<p class="created">
	Posted at {{ article.date | strftime('%d.%m.%Y %H:%M:%S') }}
</p>
<p class="perex">
	{{ article.perex | wordwrap(80) }}
</p>

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

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 <pre>{{ var_dump(users) }}</pre> 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: #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'|format_number({rounding_mode: 'floor'}) }}

{# 1000000.0000 #}
{{ '1000000'|format_number({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.

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.

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') or collect(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.

oc-twigextensions-plugin's People

Contributors

aurelien-roy avatar codebugs avatar der-on avatar emzet avatar evici avatar frontendstudio avatar gergo85 avatar jeanniton-mnr avatar ribsousa avatar vojtasvoboda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

oc-twigextensions-plugin's Issues

Conflicting dependency with Laravel 5.1

When installing this plugin in the newest version of OctoberCMS (with Laravel 5.1) you'll get a conflict on the Symonfy/Translation dependency.

Your plugin requires "symfony/translation": "^3.0" while Laravel 5.1 requires "symfony/translation": "2.7.*"

Multi language trasnlation not work

I'm having a problem with multi language site!

exemple: post published in 12/1/2017 09:25

Locale set to en works fine!
print correct 12 hours ago

When I change language to pt-br not work!
print worong 1 hora atrás

'timezone' => 'UTC',

Implementing a 'fileversion' twig filter to prevent browser from caching modified/updated asset files

Hi!

Can you implement my "fileversion" twig filter to prevent browsers from caching modified/updated asset files?

The workaround I have done to solve this "issue" is addressed there: http://stackoverflow.com/questions/728616/disable-cache-for-some-images

I think this is a common problem.

Plugin code

 public function registerMarkupTags()
    {
       return [
           'filters' => [
                'fileversion' => [$this, 'getFileVersion']
             ],
    }
    public function getFileVersion($filename)
    {
        // Remove http/web address from the file name if there is one
        // to load it locally
        $prefix = url("/");
        $filename_ = trim(preg_replace('/^' . preg_quote($prefix, '/') . '/', '', $filename), '/');

        if (file_exists($filename_))
        {
          $timestamp = filemtime($filename_);
          return $filename . "?" . date ("m.d.y.H.i.s", $timestamp);
        }else
        {
          return $filename . "?";
        }
    }

Usage code sample

<img src="{{ 'assets/images/image_file.jpg'|theme|fileversion}}" alt="an image>

Class "Twig_Extension_StringLoader" not found

basically the title says all. I went through all the folder structures but I don't know where the missing class should be. Has anyone else had this problem and knows how to fix this?

October CMS v3.1 - Upgrade Guide

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+

Event::listen('system.extendTwig', function ($twig) {
    $twig->addExtension(new \Twig\Extension\StringLoaderExtension);
});

Alternatively, you can register it in your layout code:

function onStart()
{
    $this->getTwig()->addExtension(new \Twig\Extension\StringLoaderExtension);
}

Now the following code will work:

{% set name = 'John' %}
{{ include(template_from_string("Hello {{ name }}")) }}
{{ include(template_from_string("Hurry up it is: {{ 'now'|date('m/d/Y') }}")) }}

strftime

Use the carbon() function to build a carbon object, combined with formatLocalized, available in v3.1.17+

{{ carbon(article.date).formatLocalized('%d.%m.%Y %H:%M:%S') }}

Updated Filters

uppercase

Use the str_upper filter

{{ 'Jack'|str_upper }}

lowercase

Use the str_lower filter

{{ 'JACK'|str_lower }}

ucfirst

Use the str_ucfirst filter

{{ 'jack'|str_ucfirst }}

lcfirst

Use the str_lcfirst filter

{{ 'Jack'|str_lcfirst }}

ltrim

Use the native trim Twig filter: https://twig.symfony.com/doc/2.x/filters/trim.html

rtrim

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) }}

wordwrap

This is not available.

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

Use the html_strip 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() }}

localizednumber

Install twig/intl-extra package

composer require twig/intl-extra

Register with Twig, add to boot() method in app/Provider.php file.

Event::listen('system.extendTwig', function ($twig) {
    $twig->addExtension(new \Twig\Extra\Intl\IntlExtension);
});

Use the native format_number Twig filter: https://twig.symfony.com/doc/3.x/filters/format_number.html

localizedcurrency

Follow instructions in localizednumber

Use the native format_currency Twig filter: https://twig.symfony.com/doc/3.x/filters/format_currency.html

mailto

Use the html_mailto filter

{{ '[email protected]'|html_mailto }}

var_dump

Use the dump() function

{{ dump(users) }}

revision

Use carbon() with format

carbon('now').format('m.d.y.H.i.s')

Then build the URL like so

<img src="{{ 'assets/images/image_file.jpg'|theme }}?{{ carbon('now').format('m.d.y.H.i.s') }}" alt="an image" />

sortbyfield

Use collect() with sort

collect(data).sortBy('age')

For example:

{% set data = [{'name': 'David', 'age': 31}, {'name': 'John', 'age': 28}] %}

{% for item in collect(data).sortBy('age') %}
    {{ item.name }}&nbsp;
{% endfor %}

Custom plugin and custom lang.php file

Hi, in my custom plugin's template, I want to use the time_diff function
it works perfectly but I want a custom translation from this

return [
    'diff' => [
        'empty' => 'now',
        'ago' => [
            'year' => '1 year ago|:count years ago',
            'month' => '1 month ago|:count months ago',
            'day' => '1 day ago|:count days ago',
            'hour' => '1 hour ago|:count hours ago',
            'minute' => '1 minute ago|:count minutes ago',
            'second' => '1 second ago|:count seconds ago',
        ],
        'in' => [
            'second' => 'in 1 second|in :count seconds',
            'hour' => 'in 1 hour|in :count hours',
            'minute' => 'in 1 minute|in :count minutes',
            'day' => 'in 1 day|in :count days',
            'month' => 'in 1 month|in :count months',
            'year' => 'in 1 year|in :count years',
        ],
    ],
];

to this

 return [
     'diff' => [
         'empty' => 'now',
         'ago' => [
             'year' => '1y|:count y',
             'month' => '1m|:count m',
             'day' => '1d|:count d',
             'hour' => '1h|:count h',
             'minute' => '1m|:count m',
             'second' => '1s|:count s',
         ],
         'in' => [
             'second' => 'in 1 second|in :count seconds',
             'hour' => 'in 1 hour|in :count hours',
             'minute' => 'in 1 minute|in :count minutes',
             'day' => 'in 1 day|in :count days',
             'month' => 'in 1 month|in :count months',
             'year' => 'in 1 year|in :count years',
         ],
     ],
 ];

but only for my plugin (leaving untouched the original lang.php)
Is it possible?
in which way?

Thanks

Plugin prevents password retrieval

I discovered this plugin was the cause of not being able to reset a password issue.

Once disabled, along with any other plugins that rely on this plugin as a dependancy, I was able to retrieve a forgotten admin password.

New version won't update

I cannot install the new 1.3 version, either by updating the 1.2 or by a new installation. OctoberCMS is completely up to date but here is what I get when I try to install this new version.

Problem 1
- laravel/framework[v6.0.0, ..., 6.x-dev] require symfony/http-kernel ^4.3.4 -> satisfiable by symfony/http-kernel[v4.3.4, ..., 4.4.x-dev].
- symfony/http-kernel[v4.3.4, ..., 4.4.x-dev] conflict with symfony/translation <4.2.
- vojtasvoboda/twigextensions-plugin[1.3, ..., 1.x-dev] require symfony/translation ~3.3.9 -> satisfiable by symfony/translation[v3.3.9, ..., 3.3.x-dev].
- Root composer.json requires vojtasvoboda/twigextensions-plugin ^1.3 -> satisfiable by vojtasvoboda/twigextensions-plugin[1.3, 1.x-dev].
- Root composer.json requires laravel/framework ^6.0 -> satisfiable by laravel/framework[v6.0.0, ..., 6.x-dev].

Incompatible with October v3.0

Hello, would it be possible to reduce the version of october/rain to support version 3.0? Is there something you only use in v3.1 and don't have in v3.0?

Screenshot 2022-11-23 at 14 02 40

Screenshot 2022-11-23 at 14 04 15

The style "120000.00" does not exists (localizednumber)

When trying to use localizednumber on a decimal field as follows...

{{ lot.price | localizednumber('decimal') }}

(tried it without defining it as decimal and with)
I get the following error:

The style "120000.00" does not exist. Known styles are: "decimal", "currency", "percent", "scientific", "spellout", "ordinal", "duration"

while...

$table->decimal('price', 9, 2)->nullable();

What am I not seeing here?

Translations sets days months and year with value 1

Hello,

I'm running octobercms build 447.
In English locale it gives me correct time diference eg:. 6 months ago but in any other language, I get always value 1. An example would be with locale pt-br i get 1 mês atrás instead of 6 mêses atrás.

Get v1.1.0+ to stable?

Now that October 420+ is released to stable and current stable build of this plugin doesn't work with it (#29), can you release a working version to stable? (if I remember correctly, it worked well with v1.1.0)

Thanks in advance

Breaks Forgot Password on Backend Login

When this plugin is installed, you can't use the Forgot Your Password? option when logging into the backend. When typing in the username, the following error message appears:

twig-extensions-broken

Thank you!

Having trouble with the Arabic language

hi
i add persian(fa) and arabic(ar) to lang directory and use {{ post.published_at | time_diff }} filter but persian worked and arabic not worked !!!
Having trouble with the ar

mode-js.js for October plugin - Twig Extensions (I think)

I have Twig Extensions installed / updated. I'm getting a log error 404 for /modules/backend/formwidgets/codeeditor/assets/vendor/ace/mode-js.js and I'm thinking this is part of the Twig Extension set.
The media interface is acting weird - not completing uploads. Sorry if this has nothing to do with Twig Extensions but if anyone has this file - I could use it.

Class "IntlDateFormatter" not found

Hello,

I just installed oc-twigextensions-plugin on a OC v3.1.26 and I'm getting:
Class "IntlDateFormatter" not found

I'm using the official OC docker image.

I tried to adjust the php.ini files in the attached docker shell, clearing the comment of:
extension=intl
Then I restarted my container with no luck.

How can I fix this?

Question about localizeddate

Hello,

I have some difficulties to output the month in french using the localizeddate function.

I tried :

localizeddate('none', 'none', null, null, 'F')

But it doesn't seems to work, it display me a number instead of the month.

What should I do to display, the month in French for example ?

Thanks

Plugin update error

I got this error when I update the plugin:
Update failed
"preg_match() expects parameter 2 to be string, object given (SQL: select * from system_settings where item = system_log_settings limit 1)" on line 664 of C:\xampp\htdocs\training\vendor\laravel\framework\src\Illuminate\Database\Connection.php

Then all october web site get down (failed). Including the october backend. How do I recover from that? It's urgent please.

base64_encode/decode (enhancement)

Suggest to add two function, which come handy when creating pages and wanting to send parameters, base63_encode and decode. Code could look like:

'base64_encode' => function ($string) { return  base64_encode($string); },
'base64_decode' => function ($string) { return base64_decode($string); },

It doesn't translate

Hello! First of all: a fantastic plugin and a very good job. Now to the bad...

The app.locale is correctly set to 'sv', confirmed by {{ config('app.locale') }}. But when I try this:

{{ event.published_at|strftime('%a %d %h, %H:%M') }}

... but the output is in english: Thu 18 Jan, 19:42

I've also tried other languages with the same result. It doesn't seem to work. Any tips?

Translate messages

How to get a translated output to

{{ post.published_at | time_diff }}

Does not work with new version of OctoberCMS (v40

Hi,

I just (edge) upgraded to OctoberCMS version 420 (LTS) and now I receive the following error message regarding Twix extensions plugin:

Type error: Argument 1 passed to Twig_Extensions_Extension_Date::__construct() must implement interface Symfony\Component\Translation\TranslatorInterface or be null, instance of VojtaSvoboda\TwigExtensions\Classes\TimeDiffTranslator given, called in ...plugins\vojtasvoboda\twigextensions\Plugin.php on line 208

Regards,
CB

Add support for dropdown values

Hi,

First, thanks to you for providing this plugin. Installed on every october cms project I make and it save my everyday life !

I created an issue on october CMS github page about the impossibility to display a dropdown value in frontend. When you print for example {{ model.dropdown }} to the frontend, it will display the dropdown key, not the corresponding value.

The answer of the devs (not agree) is that it's not the job of the core to know what is the value associated to that key for a dropdown. So I need to be done in an external plugin.

Instead of creating a plugin just for that, I wonder if you would accept a PR to officially add this feature into your plugin.

Thank you for your answer.

Best regards,

Alex

Composer install fails

Since I updated to v1.2.0 my composer install command fails with the following error:

The requested package composer/installers ~1.4 exists as composer/installers[v1.3.0] but these are rejected by your constraint.

I'm using Build 419 of OctoberCMS.

october 3.x

Hi. thanks for this plugin.
Any plan to make 3.x compatible ?

regards

Struggling to update to latest version

Morning Vojta,

Just a message to see if you can shed some light on an issue we are currently having.

We are trying to update the extension through SSH but for some reason it is not updating when we try. Can you provide any light into why this maybe happening or any steps we need to take so we can update to the latest version. We are currently on version 1.2.7.

Regards and thanks for your time.

Unknown "truncate" filter.

I installed the plugin on my local October 3 installation. I cant call this function...

If I remove the truncate filter, I get this error:

twig_template_from_string(): Argument #1 ($env) must be of type Twig\Environment, string given, called in /var/www/html/modules/system/classes/MarkupExtensionItem.php on line 166

Localizeddate issue

Hi

Thanks for this useful plugin.

When i used {{ post.published_at|localizeddate('medium', 'none', locale) }} i've got : Unknown "localizeddate" filter.

Other filters work well.

Does anyone have an idea ? Am i doing something wrong ?

Thanks a lot

Cannot install it with composer on latest version of OctoberCMS

I'm trying to install you package using composer: composer require vojtasvoboda/oc-twigextensions-plugin:dev-master. But I get this:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for vojtasvoboda/oc-twigextensions-plugin dev-master -> satisfiable by vojtasvoboda/oc-twigextensions-plugin[dev-master].
    - Conclusion: remove symfony/translation v2.7.16
    - Conclusion: don't install symfony/translation v2.7.16
    - vojtasvoboda/oc-twigextensions-plugin dev-master requires symfony/translation ^3.0 -> satisfiable by symfony/translation[3.0.x-dev, 3.1.x-dev, 3.2.x-dev, v3.0.0, v3.0.0-BETA1, v3.0.1, v3.0.2, v3.0.3, v3.0.4, v3.0.5, v3.0.6, v3.0.7, v3.0.8, v3.0.9, v3.1.0, v3.1.0-BETA1, v3.1.0-RC1, v3.1.1, v3.1.2, v3.1.3].
    - Can only install one of: symfony/translation[3.0.x-dev, v2.7.16].
    - Can only install one of: symfony/translation[3.1.x-dev, v2.7.16].
    - Can only install one of: symfony/translation[3.2.x-dev, v2.7.16].
    - Can only install one of: symfony/translation[v3.0.0, v2.7.16].
    - Can only install one of: symfony/translation[v3.0.0-BETA1, v2.7.16].
    - Can only install one of: symfony/translation[v3.0.1, v2.7.16].
    - Can only install one of: symfony/translation[v3.0.2, v2.7.16].
    - Can only install one of: symfony/translation[v3.0.3, v2.7.16].
    - Can only install one of: symfony/translation[v3.0.4, v2.7.16].
    - Can only install one of: symfony/translation[v3.0.5, v2.7.16].
    - Can only install one of: symfony/translation[v3.0.6, v2.7.16].
    - Can only install one of: symfony/translation[v3.0.7, v2.7.16].
    - Can only install one of: symfony/translation[v3.0.8, v2.7.16].
    - Can only install one of: symfony/translation[v3.0.9, v2.7.16].
    - Can only install one of: symfony/translation[v3.1.0, v2.7.16].
    - Can only install one of: symfony/translation[v3.1.0-BETA1, v2.7.16].
    - Can only install one of: symfony/translation[v3.1.0-RC1, v2.7.16].
    - Can only install one of: symfony/translation[v3.1.1, v2.7.16].
    - Can only install one of: symfony/translation[v3.1.2, v2.7.16].
    - Can only install one of: symfony/translation[v3.1.3, v2.7.16].
    - Installation request for symfony/translation (locked at v2.7.16) -> satisfiable by symfony/translation[v2.7.16].

This happens event if I install it from the admin panel and I do a composer update, because of the wikimedia/composer-merge-plugin added recently.
This seems to happen because of this dependency in laravel 5.1: "symfony/translation": "2.7.*".

Any advice on how to use your plugin with composer ?
Thanks!

Uppercase for swedish?

Hello there... I'm trying to get this working with swedish. When i write:'

'Välkommen' | uppercase

i get:

VäLKOMMEN

This should work:

mb_convert_case($string, MB_CASE_TITLE, "UTF-8");

Error with format_datetime()

Hello,
I have been trying now for several hours but couldn't make it work:
{{ '2019-08-07 23:39:12'|format_datetime('none', 'short', locale='fr') }} gives following error:
Unknown arguments "0", "1", "locale" for filter "format_datetime()".

{{ '2019-08-07 23:39:12'|format_datetime('none', 'short') } } gives:
Twig\Extra\Intl\IntlExtension::formatDateTime(): Argument #1 ($env) must be of type Twig\Environment, October\Rain\Argon\Argon given, called in /srv/vservers/www/stampit.gr/modules/system/classes/MarkupExtensionItem.php on line 166

I have tried on OctoberCMS 3.2.9 and 3.2.10
I have tried installing your plugin the "traditional way" with php artisan plugin:install
and with
composer require vojtasvoboda/oc-twigextensions-plugin
php artisan plugin:install VojtaSvoboda.TwigExtensions
on different websites

Any idea what is missing?
Some other functions work fine. I think just those which are related to a locale have a problem. (Locale is set and I confirmed it by displaying it on the page)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.