actu node/N show summary + body

This commit is contained in:
Bachir Soussi Chiadmi 2025-04-07 14:56:12 +02:00
parent 754cce927a
commit cc2f1e4d41

View File

@ -35,12 +35,41 @@ function quartiers_de_demain_preprocess_page(&$variables) {
* Implements hook_preprocess_HOOK() for node.html.twig.
*/
function quartiers_de_demain_preprocess_node(&$variables) {
$node = &$variables['node'];
$variables['attributes']['class'][] = 'node-type-' . $node->gettype();
$node = &$variables['node'];
$variables['attributes']['class'][] = 'node-type-' . $node->gettype();
if ($node->getType() === 'actualite'
&& $variables['view_mode'] === 'full'
&& $node->hasField('body')) {
$summary = $node->get('body')->summary;
$full = $node->get('body')->value;
if (!empty($summary) || !empty($full)) {
$variables['content']['body'] = [
'#type' => 'inline_template',
'#template' => '
{% if summary %}
<div class="body-summary">{{ summary|raw }}</div>
{% endif %}
{% if full %}
<div class="body-full">{{ full|raw }}</div>
{% endif %}
',
'#context' => [
'summary' => $summary,
'full' => $full,
],
];
}
}
}
/* implements template_preprocess_region() */
function quartiers_de_demain_preprocess_region(&$variables) {