Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2: Reference string or an array in config yaml

Tags:

yaml

symfony

In symfony2 I used config yaml below:

// config.yml
parameters:
  something: 
    content: 
      price:  2.30
      mainText: 'Some text here.'
      redText:  'This is a text here plus price: ' %price%

The %price% is wrong and gives me an error but system tells its an array, so how to point to something['content'][price]?

like image 289
TroodoN-Mike Avatar asked Sep 16 '26 01:09

TroodoN-Mike


1 Answers

Here's how you can do it

parameters:
    something.content.price: 2.30
    something:
        content:
            mainText: 'Some text here.'
            redText:  'This is a text here plus price: %something.content.price%'

Here we only have 2 parameters, something.content.price that contains a float, and something that contains an array.

This means you will only be able to access directly those 2, inside the DI configuration.

like image 61
AdrienBrault Avatar answered Sep 17 '26 21:09

AdrienBrault



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!