hook_template_preprocess_default_variables_alter

hook_template_preprocess_default_variables_alter(&$variables)

Alter the default, hook-independent variables for all templates.

Allows modules to provide additional default template variables or manipulate existing. This hook is invoked from template_preprocess() after basic default template variables have been set up and before the next template preprocess function is invoked.

Note that the default template variables are statically cached within a request. When adding a template variable that depends on other context, it is your responsibility to appropriately reset the static cache in template_preprocess() when needed:

drupal_static_reset('template_preprocess');

See user_template_preprocess_default_variables_alter() for an example.

Parameters

array $variables: An associative array of default template variables, as set up by _template_preprocess_default_variables(). Passed by reference.

See also

template_preprocess()

_template_preprocess_default_variables()

Related topics

Hooks
Define functions that alter the behavior of Drupal core.

File

core/lib/Drupal/Core/Render/theme.api.php, line 1275
Hooks and documentation related to the theme and render system.

Code

function hook_template_preprocess_default_variables_alter(&$variables) {
  $variables['is_admin'] = \Drupal::currentUser()->hasPermission('access administration pages');
}
doc_Drupal
2016-10-29 09:18:30
Comments
Leave a Comment

Please login to continue.