Manjunarth
Manjunarth

Reputation: 323

how to implement hook_theme drupal 8?

Im new to drupal,I need to render a form so i have to implement hook theme, my confusion is Under which directory I should create hook theme file in drupal 8?

// my_module.module

function custom_module_theme($existing, $type, $theme, $path) {
      return array(
         'customize_form' => array(
         'variables' => array(
         'Custom_Form' => NULL
        ),
       'render element' => 'form'
      ),
    );
}

where I have to put above file in drupal 8??

Thanks in advance.

Upvotes: 1

Views: 4658

Answers (2)

Vernit Gupta
Vernit Gupta

Reputation: 339

In your .module file

File location - module/custom/MODULENAME/MODULENAME.module
    /**
     * @file
     * Twig template for render content
     */
    function MODULENAME_theme($existing, $type, $theme, $path) {
      return [
        'theme_name_template' => [
          'variables' => ['flag' => NULL],
        ],
      ];
    }
    To Use theme function use below code 
    return ['#theme' => 'theme_name_template', '#flag' => 1];

Upvotes: 2

tpliakas
tpliakas

Reputation: 1129

If i got it right you want the folder to place your module, right? You have to put your module in a folder under /modules/custom/your_module_folder or /sites/all/modules/your_module_folder

Upvotes: 0

Related Questions