User error: "0" is an invalid render array key

Created on 16 May 2023, over 1 year ago
Updated 4 September 2023, about 1 year ago

Hello,

On a D9.5.5 + PHP 8.1.6 + v2.0.2 I get this warning:

User error: "0" is an invalid render array key in Drupal\Core\Render\Element::children() (line 98 of core/lib/Drupal/Core/Render/Element.php).
Drupal\Core\Render\Element::children(Array, 1) (Line: 404)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 456)
__TwigTemplate_c59cc24182b22b3f24b906e1d28be51c->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/custom/starter-d9-2022/templates/nodes/node--page-lycee.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 243)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)

This line in the template is for:

<span {{ telephone_attribute.addClass(telephone_classes) }}>
<strong> >>> {{ content.field_telephone_lycee|field_label }}</strong>
	{{ ':' | raw}}
	{{ content.field_telephone_lycee.0 }}
	</span>

What can I do to fix this ?
Thanks

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇫🇷France aiphes

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @aiphes
  • 🇮🇳India sumit-k

    Trie to replicate this issue with some other field, but didn't get it.

    IMO To resolve this issue, you can try the following:

    Check the structure of content.field_telephone_lycee to ensure it is an array and contains the expected data. You can use kint() or var_dump() to inspect the content variable and ensure it has the correct structure.

    If content.field_telephone_lycee is a render array, you should use the children function to access the child elements.

    I think content.field_telephone_lycee itself is rendered directly without using an index.

  • Status changed to Needs review about 1 year ago
  • 🇫🇷France aiphes

    Ok will do that and do feedback. Thanks for your advice.

  • 🇫🇷France aiphes

    So, I don't have the good debug code I guess, because no information about the fields. Here is my code:

    <ol>
      {% for key, value in _context %}
        <li>{{ key }}</li>
      {% endfor %}
    </ol>
    
    {{ dump(_context|keys) }}
    
    {{ dump(page) }}
    <h2> Debug des variables</h2>
    {{ vardumper() }}
  • 🇫🇷France aiphes

    Now the line change: {% include directory ~ '/includes/regions_inc/inc_region_zone_3.html.twig' %}

    and my include is :

    {% if region_Zone_3 is not empty %}
      <div {{ noderegion_attribute.addClass(noderegion_classes,region3_classes).setAttribute('id', 'region-zone-3') }}>
        {{ region_Zone_3 }}
      </div>
      <!-- /#region-zone_3 -->
    {% endif %}
Production build 0.71.5 2024