Skip to content

Instantly share code, notes, and snippets.

@anavdesign
Last active October 13, 2023 02:06
Show Gist options
  • Save anavdesign/0ae9148fe69f40cd97e11afbb2ca364d to your computer and use it in GitHub Desktop.
Save anavdesign/0ae9148fe69f40cd97e11afbb2ca364d to your computer and use it in GitHub Desktop.
Drupal: Themeing

Drupal Themeing

Using base_path and directory variables in twig template

{{ base_path }}
{{ directory }}
{{ base_path ~ directory }}

<img src="{{ base_path ~ directory }}/img/image.svg" />

Using base_path and directory variables in twig template

/**
 * Implements hook_preprocess().
 */
function mytheme_preprocess(array &$variables, $hook) {
  $variables['base_path'] = base_path();
}

You can use {{ active_theme_path() }} to get the path to the active theme.

Twig For Drupal 8 Development: Twig Templating

Drupal Set Message

Print Set Messages

drupal_set_message(t('Here is an external link to <a href="http://google.com">Google.</a>'), 'status');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment