I have the following in config.yml
twig:
globals:
locale_list_sg: Singapore
locale_list_cn: China
In my twig template, I will like to get the values "Singpaore" and "China" based on a argument. Therefore, I concatenate them like this and display:
{{'locale_list_' ~ countryId}}
However, the above will display locale_list_sg instead of going into config.yml and extract the values.
Use a simpler approach:
config.yml
twig:
globals:
locale_list:
sg: Singapore
cn: China
template:
{{ locale_list[country_id] }}
As far as I'm aware Twig will interpret strings as strings; it's not capable of determining variable variables... Its not pretty but a workaround (assuming you have a limited set of config options you don't mind retyping:
{{
('locale_list_' ~ countryId)|replace({
'locale_list_sg': locale_list_sg,
'locale_list_cn': locale_list_cn
})
}}
Hope that helps.