Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Пользовательская функция twig


Vetalb91
 Share

Recommended Posts

Всем привет !

в гдефолтном twig мало функций , поэтому захотел создать свою функцию но ничего не полулилось , есть пример в мануно, что-то типо :
 

Функциональных подход: 

require_once '/Twig/autoload.php';

$loader = new Twig_Loader_Filesystem('/path/to/templates');
$twig = new Twig_Environment($loader, array(
    'cache' => '/path/to/compilation_cache',
));
$twig = new Twig_Environment($loader);

// Добавляем функцию
$twig->addFunction('uniqid', new Twig_Function_Function('uniqid'));
function uniqid(){
	return uniqid();
}

ООП подход:

class Twig_Extension_UniqID extends Twig_Extension
{
    public function getName()
    {
        return 'Twig_Extension_UniqID';
    }


    public function getFunctions()
    {
        return array(
            new Twig_SimpleFunction('uniqid', 'Twig_Extension_UniqID::uniqid'),
        );
    }

    public static function uniqid()
    {
        return uniqid();
    }
}

1) не пойму ггде размещать этот код с функцией, и как он должен называться(файл)

2) какие должны быть пути к шаблону и к кэш(непонятно зачем кэш вообещё тут нужен)

3) я правильно понял что функция описывается в этом месте:(функциональный подход)
 function uniqid(){

 .........

 return uniqid();

}
Помогите плз !!!

Edited by Vetalb91
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.