I
I
Ilya Kochkin2018-09-12 17:25:47
Twig
Ilya Kochkin, 2018-09-12 17:25:47

How to make twig extension in opencart 3?

Good afternoon, don't ask me why I needed this, but I need to write a small extension for twig. in opencart3 (and I don’t really rummage in twig)
for this, in system/library/template/Twig/Extension/ I created the RrequestUrl.php file with the inherited Twig_Extension class, here is the content.

<?php

/*
 * This file is part of Twig.
 *
 * (c) 2012 Fabien Potencier
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
class Twig_Extension_RequestUrl extends Twig_Extension
{
    public function getFunctions()
    {
        return array(
            new Twig_SimpleFunction('request_uri',  'request_uri'),
        );
    }

    public function getName()
    {
        return 'request_uri';
    }
}


function request_uri()
{
    return $_SERVER['request_uri'];
}

Next, I include this extension here system/library/template/Twig/Environment.php 
$this->addExtension(new Twig_Extension_Core());
 $this->addExtension(new Twig_Extension_Debug());
 $this->addExtension(new Twig_Extension_Escaper($options['autoescape']));
 $this->addExtension(new Twig_Extension_Optimizer($options['optimizations']));
 $this->addExtension(new Twig_Extension_RequestUrl());//мое расширение

this is where i get server error 500 exactly when i type $this->addExtension(new Twig_Extension_RequestUrl());//my extension
what am i doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Kochkin, 2018-09-12
@mr_Koch

Solution - my inattention, the file and class names do not match

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question