Include widgets.js on blog posts that need it

Fixes #78
This commit is contained in:
Oliver Davies 2020-05-29 21:05:17 +01:00
parent 22533eba56
commit 79eb9bef0b
7 changed files with 90 additions and 0 deletions

View file

@ -2,6 +2,16 @@ global-styling:
css:
base:
dist/tailwind.css: {}
global-scripts:
js:
dist/js/app.js: {}
twitter:
js:
https://platform.twitter.com/widgets.js:
type: external
minified: true
attributes:
async: true
charset: 'utf-8'

View file

@ -5,6 +5,24 @@
* Functions to support theming in the Tailwind CSS theme.
*/
/**
* Implements hook_preprocess_HOOK().
*/
function opdavies_preprocess_page(array &$variables): void {
/** @var \Drupal\Core\Entity\EntityInterface $node */
if (!$node = \Drupal::routeMatch()->getParameter('node')) {
return;
}
if ($node->getType() != 'post') {
return;
}
if ($node->get('field_has_tweet')->getString()) {
$variables['#attached']['library'][] = 'opdavies/twitter';
}
}
/**
* Implements hook_preprocess_HOOK().
*/