Brian Vanegas Parra Brian Vanegas Parra - 27 days ago 11x
Twig Question

how to use split twig template field content type in drupal 8?

I need your help to solve the problem with split in twig.

  • I want to separate my var
    in an array,
    try using

    {% set array = label | split (" ")%}

returns empty

  • I want to separate a field node in an array,
    try using

    {% set array = content.field_fieldname | split (" ")%}

returns empty

if someone helps me identify what I'm doing wrong, or I indicates a guide and / or tutorial that can solve my problem. Thanks


{{ label }} is in the template as an object, I solved get the string

{% set title = items[0]['content']['#context']["value"]|split(' ', 2) %}    

<h1>{{ title[0] }}</h1>
{{ title[1] }}