Castro Crea
Castro Crea

Reputation: 83

Get the dbname on twig silex/symfony

I'm searching how i can get the "data base name" on my twig view on silex and symfony2 or 3.

I found that i can go on "app.db" and there is "_params" and "db name" witch are twig object and protected so i can access to it.

I have tried :

There is an other solution with out set the variable in the controller?? Thank in advance

Upvotes: 0

Views: 82

Answers (1)

1ed
1ed

Reputation: 3668

You can inject global variables into templates like described in the docs

http://symfony.com/doc/3.1/cookbook/templating/global_variables.html

# app/config/parameters.yml
parameters:
    database_name: name

# app/config/config.yml
twig:
    globals:
        app_database_name: '%database_name%'

{# default/index.html.twig #}
{{ app_database_name }}

Upvotes: 1

Related Questions