in my case i have a controller that it send for me the title , to the view , but i want to send the tittle and the body of the article both , i have tried to send them from the controller but it doesn't work for me
how can i send them both from the controller (title and body) ?
here is tmy controller
public function myPage() {
$data = \Drupal::service('myservice.ran');
$dataService = $data->getArticles();
return $this->renderMyPage($dataService);
}
function renderMyPage($articleObjects) {
$articles = [];
foreach ($articleObjects as $article) {
$articles[] = [
'#type' => 'html_tag',
'#html_tag' => 'h2',
'#value' => [$article->title->value,$article->body->value],
'#cache' => [
'tags' => $article->getCacheTags(),
],
];
}
return $articles;
}
#value
only takes strings. See class HtmlTag. So you either concat both values or you build a different render array. Probably best would be you usehook_theme
to add your own template.#
) in html_tag and so create a nested render array, for example a#plain_text
for the title and'#type' => 'processed_text'
for the body to output the field values safely.