I meet this situation as i wanted to add some hard coded text bevor the pagination table. It is just a demonstration how to render multiple TWIG templates within one return and can be useful to add third party code like external services (RSS, Webservices …)
1 2 3 4 5 6 7 8 9 |
$template['my_custom_html_content_headline'] = [ '#theme' => 'custom_html_content_page', '#html' => t('<h1>Headline</h1>'), ]; $template['my_custom_html_content_text'] = [ '#theme' => 'custom_html_content_page', '#html' => t('<p>Lorem ipsum ...</p>'), ]; return $template; |
The “custom_html_content_page” template theme should be defined in mymodule.module file, something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php /** * Implements hook_theme(). */ function mymodule_theme() { $templates = array('custom_html_content_page' => array( 'variables' => ['html' => NULL], 'template' => 'custom_html_content', ), ); return $templates; } |
And finally the TWIG template in the templates folder:
1 |
{{html}} |
OUTPUT:
Headline
Lorem ipsum …