Can't install Twig Extensions on OC v3.0.66

I’m trying to install the Twig Extensions plugin with:

php artisan plugin:install vojtasvoboda.twigextensions

It throws this error:

Problem 1
    - vojtasvoboda/twigextensions-plugin[dev-master, 1.3.1, ..., 1.x-dev] require symfony/translation ^3.4 || ^4.0 -> found symfony/translation[v3.4.0-BETA1, ..., 3.4.x-dev, v4.0.0-BETA1, ..., 4.4.x-dev] but the package is fixed to v6.1.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - vojtasvoboda/twigextensions-plugin[1.2.0, ..., 1.3] require symfony/translation ~3.3.9 -> found symfony/translation[v3.3.9, ..., 3.3.x-dev] but the package is fixed to v6.1.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - vojtasvoboda/twigextensions-plugin[dev-laravel54, 1.0.7, ..., 1.1.3] require symfony/translation 2.7.* -> found symfony/translation[v2.7.0-BETA1, ..., 2.7.x-dev] but the package is fixed to v6.1.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - vojtasvoboda/twigextensions-plugin[1.0.1, ..., 1.0.6] require symfony/translation ^3.0 -> found symfony/translation[v3.0.0-BETA1, ..., 3.4.x-dev] but the package is fixed to v6.1.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - Root composer.json requires vojtasvoboda/twigextensions-plugin * -> satisfiable by vojtasvoboda/twigextensions-plugin[dev-master, dev-laravel54, 1.0.1, ..., 1.x-dev].

I probably can’t just downgrade symfony/translation to ^4.0. I guess, this will brake stuff.

I may do now a fork of GitHub - vojtasvoboda/oc-twigextensions-plugin: Twig extensions plugin for OctoberCMS and try to set symfony/translation dependency to ^6.0 and see if it still works.

A lot of the extensions that were apart of that package are not now apart of OCS v3. You may be able to get away without it.

Edit (wrong word)

Very true. And I also just saw, that things like e.g. wordwrap or truncate can be done in Twig v3.x with 'Lorem ipsum'|u.wordwrap(5) or 'Lorem ipsum'|u.truncate(8, '...') repectively.

I still try to fix it, because I need it in a lot of my projects and I like to have array|shuffle.

1 Like

Not 100% sure but you can do that with the new Query builder in twig.

something like {% set collection = collection.shuffle() %}

OC3 has the query builder built in, but I could be wrong that this exists.

Thanks, but I already did a PR for the Twig Extension plugin. But I couldn’t re-implement all of the filters, because of precious time :wink:

Also I have an array to shuffle. Would {% set collection = collection.shuffle() %} also work with plain array instead of collections?

And then I find it convenient to just write 'My string'|truncate(5) instead of adding the u :man_shrugging:. Moreover if this plugin doesn’t work on OC v3.x, I would need to refactor a lot of my projects after updating…

1 Like

Ahh I see where you’re coming from.

I’m not sure if that would work on a simple array since that function uses Laravel’s eloquent lookup, but I’d try it to see if can. Probably won’t work tho.

and yeah it’s simpler to write that. I personally don’t like installing plugins as much as possible and I only like to use what I need.

Sorry for the grave digging, but since I had the exact same problem I thought it might be good to add my solution.

I also wanted to use the u.trunate() filter. I could install the vojtasvoboda.twigextensions plugin, but in the page there were some php errors coming from the extension.

Since I also wanted to keep it simple, I thought maybe there is another solution - and I found a CSS solution:

CSS Line Clamp:
<p class="truncateTitle">{{ record.name }}</p>

.truncateTitle {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

With this simple CSS I could limit the “height” of my title to three lines.

Worked like a charm. I hope this helps some people.

Here’s some additional documentation:

Please check the oc-twigextensions-plugin documentation https://github.com/vojtasvoboda/oc-twigextensions-plugin/blob/master/UPGRADE.md. This link explains the changes for OC v3.x.

I like to use Twig truncate for having a HTML container with multiple lines and these lines being truncated at the end. I was also working with the CSS ellipsis, but if you do not want to have just one line, the CSS ellipsis is kind a hard to use.

2 Likes