Answer the question
In order to leave comments, you need to log in
How to call a helper in a Twig template?
Hello!
I am using twig as a templating engine. Ordinary methods can be called object.method, but this does not work for static methods. Who faced such a task?
The module itself is github.com/tommcdo/kohana-twig
Answer the question
In order to leave comments, you need to log in
I decided! While with hardcode. Create class in folder /application/classes/Twig.php
:
<?php defined('SYSPATH') or die('No direct script access.');
class Twig extends Kohana_Twig {
protected static function env()
{
// Instantiate the base Twig environment from parent class.
$env = parent::env();
// Customize as needed.
$env->addFunction('base_url', new Twig_Function_Function('URL::base'));
return $env;
}
} // End Twig
{% block content %}
{{ base_url() }}
{% endblock %}
/kohana/
Twig is very customizable, you can write your own extension, in which you can add your own functions, filters, post-processors, and whatever.
Even the basic functions of Twig are highlighted in it in the Core extension, you can see how it is done. And read the documentation, it is very short and understandable.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question