How to combine two string in twig?

前端 未结 4 2024
粉色の甜心
粉色の甜心 2021-02-01 12:25

I want to do something like this:

{% set c=a+b %}

Where a and b are strings.
How can I do it?

4条回答
  •  清酒与你
    2021-02-01 12:57

    Use the "~" operator. This will concatenate your two strings. The "+" operator cannot be used to combine strings.

    You would get this:

    {% set c=a~b %}
    

    More info: The "+" operator: Adds two objects together (the operands are casted to numbers).

提交回复
热议问题