0

I work on a symfony project and I want to do something like this in my app/config/parameters.yml

dev.google.api.key: foo
google: %%kernel.environment%.google%

It not works.

I explain : I want to have the variable google to have values depending my environment (env or prod).

So I defined two variable :

dev.google.api.key: foo
prod.google.api.key: bar

I want to have my variable google to be filled with content depending on the environment. The environment is in the variable

%kernel.environment%

So if I do :

google: %kernel.environment%.google

Google is equal to "dev.google" but I want to this string to be evaluated like this %dev.google%. But %%kernel.environment%.google% not works.

An idea ? Thanks

ReaperSoon
  • 765
  • 7
  • 23
  • I don't think it is possible. But I think you complexify your need. Do you really need to declare this parameters ? you have config_dev.yml and config_prod.yml file – Arno Sep 27 '17 at 15:44
  • Yes but a cannot accès content from config.yml on my twig files. I want to add this vars to my twig : globals. But to keep this variables in parameters to avoid adding variables in multiple files. But give up, I put my vars in config_env. Thanks – ReaperSoon Sep 27 '17 at 17:33
  • 1
    Possible duplicate of [symfony: How to set configuration parameters files for different environments?](https://stackoverflow.com/questions/29328186/symfony-how-to-set-configuration-parameters-files-for-different-environments) – gp_sflover Jan 04 '18 at 16:13

1 Answers1

3

You can try something like this:

in your config_dev.yml:

parameters:
    google.api.key: foo

in your config_prod.yml:

parameters:
    google.api.key: bar

in your config.yml:

google: %google.api.key%

Or

Create paramater_dev.yml with

parameters:
    google.api.key: foo

Create paramater_prod.yml with

parameters:
    google.api.key: bar

in your config_dev.yml:

imports:
    - { resource: paramater_dev.yml }
    - { resource: config.yml }

in your config_prod.yml:

imports:
    - { resource: paramater_prod.yml }
    - { resource: config.yml }

in your config.yml:

google: %google.api.key%
doydoy44
  • 5,720
  • 4
  • 29
  • 45