Back to Top

Symfony – Use services in twig

Updated 11 February 2016

Code-Snippet

Symfony Service : Service is any PHP object that performs some sort of “global” task.

To access service in twig , you need to define service in config.yml files. Following is the example how to defined servies in config.yml :

twig:
    globals:
        test_service: "@test.service"

Now you service is globally accessible in twig, you can use service by simply
using the following statement:

{% set id = test_serive.getTestId() %}

Searching for an experienced
Symfony Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home