How do I concatenate a calculated result to some existing text in Twig?

Jaeger

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

Alessandro Minoccheri

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I get text from a calculated String to a TextView field?

From Dev

how to concatenate Sql query result With some strings?

From Dev

How do I concatenate text that contains the escape character "\"

From Dev

How do I partial refresh elements which were rendered before my result was calculated?

From Java

How to concatenate strings in twig

From Dev

How do I iterate over array result from findBy Doctrine query in Twig template

From Java

How do I concatenate strings?

From Dev

How do I create an automated calculated column?

From Dev

How Do I Store A Calculated Value In Rails

From Dev

How do i increase the transaction result text in phpMyAdmin?

From Dev

In Oracle how do you perform a calculation depending on the previous calculated result

From Java

How do I scale all the text in a ggplot by some multiple?

From Dev

In Inno Setup, how do I center some text in the window?

From Dev

how do I display rating icons to the right of some text

From Dev

In MigraDoc, how do I surround some text and a table with the same border?

From Dev

How do I duplicate a PDF with some text replacement and redaction

From Dev

How do I get a picture (flag) in the same line as some text?

From Dev

How to add some text between date and hour with twig localizeddate extension

From Dev

How can I concatenate a column into existing column of list in pandas that is not None?

From Dev

Using rx.js, how do I emit a memoized result from an existing observable sequence on a timer?

From Dev

How do I concatenate a user form text box value with an arbitrary string?

From Dev

How do I concatenate cell values and text together using Excel VBA?

From Dev

How do I check for the existence of a bundle in twig?

From Dev

How do I check for the existence of a bundle in twig?

From Dev

How can i view Result of Database from doctrine in twig

From Dev

How do I concatenate a string and wstring?

From Dev

How do I concatenate multiple files in Gradle?

From Java

How do I concatenate strings and variables in PowerShell?

From Java

How do I concatenate or merge arrays in Swift?

Related Related

  1. 1

    How do I get text from a calculated String to a TextView field?

  2. 2

    how to concatenate Sql query result With some strings?

  3. 3

    How do I concatenate text that contains the escape character "\"

  4. 4

    How do I partial refresh elements which were rendered before my result was calculated?

  5. 5

    How to concatenate strings in twig

  6. 6

    How do I iterate over array result from findBy Doctrine query in Twig template

  7. 7

    How do I concatenate strings?

  8. 8

    How do I create an automated calculated column?

  9. 9

    How Do I Store A Calculated Value In Rails

  10. 10

    How do i increase the transaction result text in phpMyAdmin?

  11. 11

    In Oracle how do you perform a calculation depending on the previous calculated result

  12. 12

    How do I scale all the text in a ggplot by some multiple?

  13. 13

    In Inno Setup, how do I center some text in the window?

  14. 14

    how do I display rating icons to the right of some text

  15. 15

    In MigraDoc, how do I surround some text and a table with the same border?

  16. 16

    How do I duplicate a PDF with some text replacement and redaction

  17. 17

    How do I get a picture (flag) in the same line as some text?

  18. 18

    How to add some text between date and hour with twig localizeddate extension

  19. 19

    How can I concatenate a column into existing column of list in pandas that is not None?

  20. 20

    Using rx.js, how do I emit a memoized result from an existing observable sequence on a timer?

  21. 21

    How do I concatenate a user form text box value with an arbitrary string?

  22. 22

    How do I concatenate cell values and text together using Excel VBA?

  23. 23

    How do I check for the existence of a bundle in twig?

  24. 24

    How do I check for the existence of a bundle in twig?

  25. 25

    How can i view Result of Database from doctrine in twig

  26. 26

    How do I concatenate a string and wstring?

  27. 27

    How do I concatenate multiple files in Gradle?

  28. 28

    How do I concatenate strings and variables in PowerShell?

  29. 29

    How do I concatenate or merge arrays in Swift?

HotTag

Archive