Created
March 6, 2023 10:55
-
-
Save prashantdsala/28cf2d4f372e1d0555ede9b5d0d899cd to your computer and use it in GitHub Desktop.
How to create a custom template file in Drupal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
/** | |
* @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