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

3
  • 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 Commented Sep 27, 2017 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 Commented Sep 27, 2017 at 17:33
  • 1
    Possible duplicate of symfony: How to set configuration parameters files for different environments? Commented Jan 4, 2018 at 16:13

1 Answer 1

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%
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.