Hi!
I’m running into an issue with my email module.
This is the code:
{% set footer_data = {
'The Netherlands': {
'company_name': 'Company B.V.',
'address': 'Street 200',
'city': 'Amsterdam',
'state': 'Noord-Holland',
'zip_code': '2000',
'country': 'The Netherlands'
},
'Germany': {
'company_name': 'Company B.V.',
'address': 'Street 200',
'city': 'Emsbüren',
'state': 'Niedersachsen',
'zip_code': '2000',
'country': 'Germany'
},
'France': {
'company_name': 'Company B.V.',
'address': 'Street 200',
'city': 'Paris',
'state': 'Île-de-France',
'zip_code': '2000',
'country': 'France'
},
'Belgium': {
'company_name': 'Company B.V.',
'address': 'Street 200',
'city': 'Antwerpen',
'state': 'Antwerpen',
'zip_code': '2000',
'country': 'Belgium'
},
'Denmark': {
'company_name': 'Company B.V.',
'address': 'Street 200',
'city': 'København K',
'state': 'Hovedstaden',
'zip_code': '2000',
'country': 'Denmark'
},
'Spain': {
'company_name': 'Company B.V.',
'address': 'Street 200',
'city': 'Barcelona',
'state': 'Barcelona',
'zip_code': '2000',
'country': 'Spain'
},
'United Kingdom': {
'company_name': 'Company B.V.',
'address': 'Street 200',
'city': 'London',
'state': 'London',
'zip_code': '2000',
'country': 'United Kingdom'
}
} %}
{% set country = contact.country|string %}
<b>Footer TEST:</b><br>
Contact Country: {{ contact.country|pprint }}<br>
Dictionary Keys: {{ footer_data.keys() }}<br>
Country: {{ country|pprint }}<br>
Contact: {{ contact }}<br>
<b>Company name:</b>{{ footer_data[country].company_name }}
{% set countries = ['The Netherlands', 'Germany', 'France', 'Belgium', 'Denmark', 'Spain', 'United Kingdom'] %}
{% for c in countries %}
{% if c == country %}
<!-- Do stuff -->
{% endif %}
{% endfor %}
I’m trying to show content from a dictionary based on the users country field. Problem is, when I try and take the variable containing the country STRING and place it in the code below:
{{ footer_data[country].company_name }}
It doesn’t show anything.
When I replace country with ‘Germany’ for example, so a literal string it does work… I’ve checked every bit. Using Pprint shows me that it’s a string. I’ve tried using “|string” but that doesn’t do anything. I even tried adding quotes myself but that doesn’t work either.
I’m not sure what’s wrong. Any help is greatly appreciated!
Thanks in advance!