Using a custom function in twig

后端 未结 4 1893
失恋的感觉
失恋的感觉 2021-02-02 10:21

In my template I want to output the server timezone.

My template has something like

{{ getservertimezone }}

Then in the services.yml co

4条回答
  •  情话喂你
    2021-02-02 10:47

    Use getFunctions() instead of getFilters()

    public function getFunctions()
    {
        return array(
            new \Twig_SimpleFunction('server_time_zone', array($this, 'getServerTimeZone')),
        );
    }
    

    Twig filters are used to filter some value.

    {{ "some value" | filter_name_here }}
    

    Btw, you can define both filters and functions in the same class.

提交回复
热议问题