I want to get a field value from a node that I can use in the html--front.html.twig template file.
I can create a new variable, for example with $variables['custom_twig_variable'] = 'Some important value';
.
Then in the template file, I would simply get that value with {{ custom_twig_variable }}
.
I don't know how to get the field value from $variables
, the argument passed to the theme hook, whose content is the following one.
Array (
[user] => Drupal\Core\Session\AccountProxy Object (
[requestStack:protected] => Symfony\Component\HttpFoundation\RequestStack Object (
[requests:Symfony\Component\HttpFoundation\RequestStack:private] => Array (
[0] => Symfony\Component\HttpFoundation\Request Object (
[attributes] => Symfony\Component\HttpFoundation\ParameterBag Object (
[parameters:protected] => Array (
[_system_path] => node/4
[_controller] => \Drupal\node\Controller\NodeViewController::view
[_title_callback] => \Drupal\node\Controller\NodeViewController::title
[node] => Drupal\node\Entity\Node Object (
[values:protected] => Array (
[vid] => Array (
[x-default] => 4
)
[field_background_color] => Array (
[x-default] => Array (
[0] => Array (
[value] => ff00ff
)
)
)
)
)
)
)
)
)
)
)
)
How do I get the value of field_background_color?