Shaun
Shaun

Reputation: 185

Add variable to a string in Twig

I am trying to modify the value 7 in the following twig code:

{{ "now"|date_modify("+7 days")|date("Y/m/d") }}

The above works fine, but if I try this I get an error:

{{ "now"|date_modify("+" . user.days . " days")|date("Y/m/d") }}

Is it possible to edit the number of days dynamically in twig?

Upvotes: 1

Views: 424

Answers (1)

doydoy44
doydoy44

Reputation: 5772

Try to use ~ to concatenate like this :

{{ "now"|date_modify("+" ~ user.days ~ " days")|date("Y/m/d") }}

Upvotes: 1

Related Questions