1

I try to print field_tags inline and comma separated. My code in node.html.twig:

<p>{{ content.field_tags | join(', ') }}</p>

This return error message: The website encountered an unexpected error. Please try again later.

Whats wrong? Help.

  • I doubt content.field_tags is a string...check your watchdog and server logs, the real error message should be in there – Clive Nov 11 '15 at 14:11
  • Nope. Is array from field taxonomy term list. If I print {{ content.field_tags[0] }} — response is first element from field. – Platon Nov 11 '15 at 14:59
  • There may be other way to analog <?php print implode(', ', $array); ?> from D7 for D8 Twig? – Platon Nov 11 '15 at 15:03
  • Oh sorry, I read "join" as "split" for some bizarre reason :) Are you sure content.field_tags is an array and not an object? – Clive Nov 11 '15 at 15:24
  • Even if the content.field_tags[0] renders properly, it does not mean it is a string. I suggest you check out the structure in preprocess function in php, not twig. – user21641 Nov 11 '15 at 15:52
1

Anything in content is a render array, you can't use functions like that on those directory.

You can loop over it and print out each item, that works as it is then automatically rendered.

  • And you can check loop.last if you want to emulate the join filter. – Andy Aug 24 '17 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.