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

Comments

aiphes created an issue. See original summary.

aiphes’s picture

Issue summary: View changes
sumit-k’s picture

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.

sumit-k’s picture

Status: Active » Needs review
aiphes’s picture

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

aiphes’s picture

With:

<ol>
  {% for key, value in _context %}
    <li>{{ key }}</li>
  {% endfor %}
</ol>

{{ dump(_context|keys) }}

{{ dump(page) }}
<h2> Debug des variables</h2>
{{ vardumper() }}

Result is:

  "field_telephone_lycee" => array:1 [▼
          "x-default" => array:1 [ …1]
        ]
   "field_telephone_lycee" => array:1 [▼
          "x-default" => Drupal\Core\Field\FieldItemList {#3057 ▼
            #definition: Drupal\field\Entity\FieldConfig {#2165 ▶}
            #name: "field_telephone_lycee"
            #parent: Drupal\Core\Entity\Plugin\DataType\EntityAdapter {#2196 ▶}
            #_serviceIds: []
            #_entityStorages: []
            #stringTranslation: null
            #typedDataManager: Drupal\Core\TypedData\TypedDataManager {#840 …22}
            #list: array:1 [ …1]
            #langcode: "und"
          }
        ]
aiphes’s picture

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 %}
grevil’s picture

Version: 2.0.2 » 2.0.x-dev
Status: Needs review » Postponed (maintainer needs more info)

Is this still a problem in latest dev?