I’m attempting to vary Drupal Development header background picture of my web site primarily based on Drupal Development present node. I’ve added a picture discipline to my content material sort, field_hero_image
, and, in preprocess operate mytheme_preprocess_page(&$variables)
, I get Drupal Development picture url and attempt to inject it in Drupal Development web page, as inline css:
operate mytheme_preprocess_page(&$variables) { $node = $variables['node']; if ($node) { $path = file_create_url($node->field_hero_image->entity->getFileUri()); $variables['page']['#attached']['css'] = array( 'information' => '.header-wrapper { background:url(' . $path . ') heart heart no-repeat !vital; background-size: cowl;}', 'sort' => 'inline', ); } }
or
operate mytheme_preprocess_page(&$variables) { $node = $variables['node']; if ($node) { $path = file_create_url($node->field_hero_image->entity->getFileUri()); $variables['#attached']['library'][] = array( 'information' => '.header-wrapper { background:url(' . $path . ') heart heart no-repeat !vital; background-size: cowl;}', 'sort' => 'inline', ); } }
None of this works.
Is there a strategy to inject css from Drupal Development preprocess operate? I do know that I can get Drupal Development path worth, put it in $variables and use it in twig. However this does not appear a clear answer to me.