I have problem with template for my custom page in my module.
I use hook_theme()
to define my twig file. And when I check in hook_theme_registry_alter()
I see my new template file but when I try use it it is not working.
My code :
file: first.module
/**
* Implement hook_theme().
*/
function first_theme($existing, $type, $theme, $path) {
return array(
'testtwig' => array(
'template' => 'testtwig',
'variables' => array('test_var' => NULL),
),
);
}
Controller:
/**
* @file
* Contains \Drupal\first\Controller\FirstController.
*/
namespace Drupal\first\Controller;
use Drupal\Core\Controller\ControllerBase;
class FirstController extends ControllerBase {
public function content() {
return array(
'#theme' => 'testtwig',
'#test_var' => t('sss'), //$output,
);
}
}
Error:
Template "modules/custom/first/templates/testtwig.html.twig" is not defined (Drupal\Core\Template\Loader\ThemeRegistryLoader: Unable to find template "modules/custom/first/templates/testtwig.html.twig" in the Drupal theme registry.).
modules/custom/first/templates
– Dziabodo