3.5 Demonstrate ability to write template pre-process functions for overriding custom output

Review how and where to access the HTML preprocess function and the page preprocess function. Review where to access the body class.

Pre-process functions allow variables to be manipulated before rendering. Drupal.org lists all available preprocess functions. Preprocess functions are defined in the THEME_NAME.theme file or in a custom module.

For example

/*
 * Implements hook_preprocess_html() for html.html.twig.
 */

function THEME_NAME_preprocess_html(&$variables) {

}

Some variables that are available to html.html.twig and hook_preprocess_html() include * doctype * html * body tags

/*
 * Implements hook_preprocess_page() for page.html.twig.
 */

function THEME_NAME_preprocess_page(&$variables) {

}

Some variables that are available to html.html.twig include page elements and regions.

Other Resources

Last updated