I work in D8, I create a custom module first_module. By modules create a url and display all nodes by *.html.twig file.
Write code in controller.php
public function contentthree() {
$connection = Database::getConnection();
$query = $connection->select('node', 'n');
$query->fields('n', ['nid', 'type']);
$groups = $query->execute()->fetchAll();
foreach ($groups as $group) {
$events[] = [$group->nid, $group->type];
}
return [
'#theme' => 'first_module_display',
'#events' => $events,
];
}
In *.module
function first_module_theme($existing, $type, $theme, $path) {
return [
'first_module_display' => [
'variables' => ['events' => NULL],
'template' => 'first-module-list',
],
];
}
function _get_node_details() {
$output = 'Welcome D8';
$output .= 'Node Details';
return $output;
}
and create templates first-module-list.html.twig and display data
{%for key, data in events %}
{%for key1, data1 in data %}
{{ data1 }}
{% endfor %}
{% endfor %}
work fine and showing data correct. But, my question is how to call function _get_node_details()
and how to render node details in first-module-list.html.twig
files?