A
A
Alexey Alekseev2018-11-20 21:09:38
symfony
Alexey Alekseev, 2018-11-20 21:09:38

Symfony 3/4: How to access a service from a template?

Hello!
Created my service in Symfony 3.4, example:

<?php

namespace AppBundle\Service;

class Favourites
{
    public function parse ($str)
    {
        return strtoupper($str);
    }
}

How do I now access it from a Twig template?
As I understand it, it is necessary to register it somewhere in the configs so that it becomes available.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bears, 2018-11-20
@bears

Like this
https://symfony.com/doc/current/templating/global_...
UPD: but if you have simple manipulations, it's better to create your own twig functions/filters
https://symfony.com/doc/current/templating /twig_ex...
You can also access services in these functions/filters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question