Updating object properties in twig

后端 未结 6 789
借酒劲吻你
借酒劲吻你 2020-12-29 18:30

Is there a way to update an object\'s property in twig?

An object like the following is passed to twig:

object
   property1
   property2
6条回答
  •  囚心锁ツ
    2020-12-29 18:48

    If your property is array (object->property['key']) you can do something like this:

    {% set arr = object.property|merge({"key":['some value']}) %}
    {{ set(object, 'property', arr) }}
    

    That equivalent to:

    this->property['key'][] = 'some value';
    

提交回复
热议问题