Skip to content

Instantly share code, notes, and snippets.

@prashantdsala
Created March 6, 2023 10:55
Show Gist options
  • Save prashantdsala/28cf2d4f372e1d0555ede9b5d0d899cd to your computer and use it in GitHub Desktop.
Save prashantdsala/28cf2d4f372e1d0555ede9b5d0d899cd to your computer and use it in GitHub Desktop.
How to create a custom template file in Drupal
<?php
/**
* @file
* Primary module hooks for Custom Template module.
*/
/**
* Implements hook_theme().
*/
function custom_template_theme() {
return [
'example' => [
'variables' => ['foo' => NULL],
],
];
}
/**
* Prepares variables for example template.
*
* Default template: example.html.twig.
*
* @param array $variables
* An associative array containing:
* - foo: Foo variable description.
*/
function template_preprocess_example(array &$variables) {
$variables['foo'] = 'bar';
}
{#
/**
* @file
* Default theme implementation to display something.
*
* Available variables:
* - foo: Foo variable description.
*
* @see template_preprocess_example()
*
* @ingroup themeable
*/
#}
<div class="wrapper-class">
{{ foo }}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment