Skip to content

Instantly share code, notes, and snippets.

@sachbearbeiter
Created January 30, 2015 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sachbearbeiter/0213ea70dd1d258fdafc to your computer and use it in GitHub Desktop.
Save sachbearbeiter/0213ea70dd1d258fdafc to your computer and use it in GitHub Desktop.
D8: Get the current user ID in theme file and set a variable via MYTHEME_preprocess_page to use it in page.html.twig.
{# isAdmin? #}
{% if UserID == '1' %}
{{ kint() }}
{% endif %}
/**
* Implements hook_preprocess_HOOK() for page templates.
*/
function MYTHEME_preprocess_page(&$variables) {
$UserID = $variables['user']->id();
$variables['UserID'] = $UserID;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment