I’ve been wrestling with Drupal 8 for some time now and have run into a little problem.
I want to get a field value from a content type that I can use in my html--front.html.twig
. I can create a new variable that I can use in the twig template i.e
$variables['custom_twig_variable'] = 'Some important value';
Then in my twig template I would simply call this like this
{{ custom_twig_variable }}
The thing here is that I don’t now how to “reach” my field value in the array $variables
that is passed into the preprocess_html
function.
Array ( [user] => DrupalCoreSessionAccountProxy Object ( [requestStack:protected] => SymfonyComponentHttpFoundationRequestStack Object ( [requests:SymfonyComponentHttpFoundationRequestStack:private] => Array ( [0] => SymfonyComponentHttpFoundationRequest Object ( [attributes] => SymfonyComponentHttpFoundationParameterBag Object ( [parameters:protected] => Array ( [_system_path] => node/4 [_controller] => DrupalnodeControllerNodeViewController::view [_title_callback] => DrupalnodeControllerNodeViewController::title [node] => DrupalnodeEntityNode Object ( [values:protected] => Array ( [vid] => Array ( [x-default] => 4 ) [field_background_color] => Array ( [x-default] => Array ( [0] => Array ( [value] => ff00ff ) ) ) ) ) ) ) ) ) ) ) )
How do I read the value of field_background_color
?
Sponsored by SupremePR