Git Product home page Git Product logo

Comments (14)

TimFoerster avatar TimFoerster commented on May 29, 2024 2

This is because ocms3 uses twig v3, instead of v1/2 instead and there whole extension system was changed.

from oc-twigextensions-plugin.

artisticdigital avatar artisticdigital commented on May 29, 2024 1

I posed this to OCMS help and got the following response:
"Generally, the Twig classes have been renamed to use namespaces. For example, a class can be namespace with the following conversion Twig_Extension_StringLoader → Twig\Extension\StringLoader"
So at the very least it appears to be a naming issue. I'm going through and trying to adjust and will have a note into vojtasvoboda.

from oc-twigextensions-plugin.

vojtasvoboda avatar vojtasvoboda commented on May 29, 2024 1

Yes sure, why not. Do you have a list of new functions we can use? I can update readme with that.

Anyway, there is a lot of filters we can use in October 3 and it would be fine to have October 3 100% compatible version.

from oc-twigextensions-plugin.

vojtasvoboda avatar vojtasvoboda commented on May 29, 2024 1

Hello all (@mwahlmueller, @markandmedia, @TimFoerster, @artisticdigital, @maki3000), new version of the plugin is available on the market and is compatible with October 3.1 and PHP 8.0.

A lot of filters/functions were removed because they are part of the October CMS now. See UPGRADE.MD guide to learn more.

On the other hand, some new filters/functions were added: country_timezones, country_name, currency_name, currency_symbol, language_name, locale_name, timezone_name, format_currency, format_number and format_*_number, format_datetime, format_date and format_time - they are part of the official twig/intl-extra package.

from oc-twigextensions-plugin.

markandmedia avatar markandmedia commented on May 29, 2024

We are getting the same error, but only in a test project running octoberCMS V3

from oc-twigextensions-plugin.

potioncodes avatar potioncodes commented on May 29, 2024

Thank you for your answer. I am currently downgrading again to 2.* and trying to avoid automatically installing the 3.*.
I think the issue is on the new Laravel / Symphony Twig support.

from oc-twigextensions-plugin.

potioncodes avatar potioncodes commented on May 29, 2024

@TimFoerster yes you are right I downgraded to 2.2 and it works perfectly.

from oc-twigextensions-plugin.

vojtasvoboda avatar vojtasvoboda commented on May 29, 2024

Any tips on how to solve this? Create a new plugin just for v3? Create legacy Git branch only for v1/v2?

from oc-twigextensions-plugin.

potioncodes avatar potioncodes commented on May 29, 2024

@vojtasvoboda I think the main problem was the String or Array Extension as they are sometimes (as I've read) not loaded by default or have other names now. I tried to manually define some "old" methods directly where some errors "not defined etc." occurred and it worked in the 3.x. But it was to exhausting to find all twig changes and badly put them in the file where they were needed so I downgraded oct. CMS.

from oc-twigextensions-plugin.

TimFoerster avatar TimFoerster commented on May 29, 2024

@vojtasvoboda releasing it as v2 should be fine.
But IMHO ocms should provide all default available filters by twig https://twig.symfony.com/doc/3.x/filters/index.html
which makes this plugin for most developers obsolete.
Maybe you should start an discussion with Sam about it. You can also take a look modules/cms/twig/Extension.php to see how they implemented them.

from oc-twigextensions-plugin.

vojtasvoboda avatar vojtasvoboda commented on May 29, 2024

I've tried changing all namespaces from Twig_Extension_* to Twig\Extension*, but now it throws Class "Twig_Extension" not found on plugins/vojtasvoboda/twigextensions/vendor/twig/extensions/lib/Twig/Extensions/Extension/Text.php. There is a problem with Twig v2 vs Twig v3 as @TimFoerster mentioned.

So I set compatibility with Twig plugin just for October v1 and v2. October v3 stays untested for now.

from oc-twigextensions-plugin.

TimFoerster avatar TimFoerster commented on May 29, 2024

ocms 2/3 recevied some new twig methods/function with a new Carbon version. How about to abandoned this plugin for ocms3 and write a document with alternatives for each method? This should be less work compared to upgrading it to Twig 3.

For example mailto is implemented in ocms now:
{{ [email protected] | mailto }} => <a href="mailto: {{ html_email('[email protected]')|raw }}">[email protected]</a>

Or using Carbon 2
{{ post.published_at | localizeddate('medium', 'none', locale) }} => post.published_at.locale(locale).isoFormat('L')

from oc-twigextensions-plugin.

maki3000 avatar maki3000 commented on May 29, 2024

I actually would like to do a version of this plugin for OC v3.x. Or is already somebody else into it?

But with my limited PHP knowledge, I have some question. Maybe I would achieve it with some help.

So, I had a look at modules/cms/twig/Extension.php and thought, that like following it should work. I thought, I do just the uppercase filter as a start and later add all others, when I know, how to do it.

This is the boot method in Plugin.php:

public function boot()
    {
        // init Twig
        $twig = $this->app->make('twig.environment');
        // add new twig extensions
        $twig->addExtension(new OcTwigExtension());
}

Then I created a new class OcTwigExtension:

class OcTwigExtension extends TwigExtension
{
    /**
     * getFunctions returns a list of functions to add to the existing list.
     * @return array
     */
    public function getFunctions()
    {
        return [
            new TwigSimpleFunction('uppercase', [$this, 'uppercaseFunction'], ['is_safe' => ['html']]),
        ];
    }

    /**
     * uppercaseFunction converts text uppercase.
     * @return bool
     */
    public function uppercaseFunction($string)
    {
        return (string) mb_convert_case($string, MB_CASE_UPPER, "UTF-8");
    }
}

But the uppercase filter seems to be unknown like this.

from oc-twigextensions-plugin.

daftspunk avatar daftspunk commented on May 29, 2024

Hello, most of this functionality is now included in the core. See issue #72 for details.

from oc-twigextensions-plugin.

Related Issues (20)

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.