Twig split doesn't work properly when debug is set to on. I'm splitting title strings "backend developer", "content management", "project management" in two by using the following code:

{% set titles = fields.title.content|split(' ', 2) %}
<div class="heading-1">{{ attribute(titles, 0) }}</div>
<div class="heading-2">{{ attribute(titles, 1) }}</div>

If I turn off Twig debugging it works fine and displays correctly like this:
http://i.imgur.com/xW79S6R.png

But with Twig debugging on it displays the theme_hook suggestions:
http://i.imgur.com/nuOdH7i.png

Screenshots attached as well.

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

mahammedzkhan created an issue. See original summary.

mahammedzkhan’s picture

Component: views.module » field system
swentel’s picture

Component: field system » theme system

Moving to better component.

joelpittet’s picture

Not sure how to resolve this one off hand but grab the value instead of the content And split that? Likely you don't want to deal with HTML anyways?

Cottser’s picture

Issue tags: -drupal8, -split, -Debug

Yes I agree with what @joelpittet said. Splitting HTML is going to be tricky and I don't think this is something core should try to hold your hand on.

I would argue this is not a bug but a result of how twig debug was designed to work.

joelpittet’s picture

Status: Active » Postponed (maintainer needs more info)

This is likely going to be closed as "works as designed", but postponing on my question in #4

joelpittet’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Triage, closing as I mentioned to myself in #6. Re-open if you have more details to add.

AdamPS’s picture

I am tentatively re-opening this one as part of a larger META initiative #2914733: [META] twig debug can break parts of site.

Even if we can't solve this problem automatically, I feel it could be advantageous to document as far as possible all ways that turning twig debug on might break a site.

You could argue that now that I have linked this to the META that already provides some documentation, so I don't mind if you want to close it again.