Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
Screen Shot 2016-01-26 at 10.45.56.png | 141.88 KB | mahammedzkhan | |
Screen Shot 2016-01-26 at 10.35.17.png | 164.01 KB | mahammedzkhan |
Comments
Comment #2
mahammedzkhan CreditAttribution: mahammedzkhan at Pàu commentedComment #3
swentel CreditAttribution: swentel as a volunteer commentedMoving to better component.
Comment #4
joelpittetNot sure how to resolve this one off hand but grab the
value
instead of thecontent
And split that? Likely you don't want to deal with HTML anyways?Comment #5
star-szrYes 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.
Comment #6
joelpittetThis is likely going to be closed as "works as designed", but postponing on my question in #4
Comment #7
joelpittetTriage, closing as I mentioned to myself in #6. Re-open if you have more details to add.
Comment #8
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedI 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.