I have several variables available that allow me to display years. For example,
{{ vars['cotisation_max_year'] }} => 2016
I have another variable that look like the following:
{{ vars.cotisations['cotisation_2014'] }}
That display a query's result.
If I do {{ vars['cotisation_max_year'] - 1 }}
, I get 2015, and if I do
{% set annee = vars['cotisation_max_year'] %} // Let's simplify
{{ vars.cotisations['cotisation_' ~ annee ] }}
I get the result for 2016. However, if I do the following:
{{ vars.cotisations['cotisation_' ~ annee - 1 ] }}
Nothing shows up.
Is there a way to display the result anyway? I couldn't find anything that would solve my problem on the Twig documentation or on SO
try this instead of complicate the code:
{% set annee = vars['cotisation_max_year'] -1 %} // Let's simplify
{{ vars.cotisations['cotisation_' ~ annee ] }}
Or this (never tried):
{% set annee = vars['cotisation_max_year'] %} // Let's simplify
{{ vars.cotisations['cotisation_' ~ (annee - 1) ] }}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments