we have this code in template.theme but when we go to view the web, the page show a error as this: "isEven" is an invalid render array key /web/core/lib/Drupal/Core/Render/Element.php . I dont understand very good Drupal and as works it.
function fcjc_bootstrap_preprocess_paragraph(&$variables)
{
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = $variables['paragraph'];
if ($paragraph->getType() === 'image_text_full_width' || $paragraph->getType() === 'imaxe_texto_biografia_') {
$variables['isEven'] = $variables['elements']['isEven'];
}
}
function fcjc_bootstrap_preprocess_field__field_image_text_section(&$vars)
{
foreach ($vars['items'] as $delta => &$item) {
$classname = ($delta % 2 == 0 ? 'even' : 'odd');
$item['attributes']->setAttribute('class', $classname);
$item['content']['isEven'] = ($delta % 2 == 0);
}
}
In paragraph.twig I have this:
<div class=" image col-sm-4 col-xs-12 {% if isEven %}right-shadow{% else %}left-shadow col-sm-push-8{% endif %}">
Can Somebody can help me? please. Thx
$item['content']['isEven'] = ($delta % 2 == 0);
you're adding something into the $item['content'] render array which isn't renderable$item['content']['isEven']
with a single value? If so, it might be better to defineisEven
as a property, so that it is written as$item['content']['#isEven']
. You can add any arbitrary properties to a render array.