Sometimes you need to get a field in the page.html.twig template. The template hierarchy suggests that node values (fields) should be rendered in the node.html.twig template and page.html.twig is the parent template that should be dealing with regions etc.
The solution is use THEME_preprocess_page() to reference the node and get the field. There are 3 ways to do this (probably more) but the examples below show the array and simple string methods. The field is 'Video Id' which has a machine name of 'field_video_id'.
If my theme was called myD9theme then the following would be in the myD9theme.theme file.
function myD9theme_preprocess_page(&$variables) { if(isset($variables['node'])){ $nodeType = $variables['node']->bundle(); if($nodeType == 'video'){ // Method 1 (returns array) $video_id = $variables['node']->field_video_id->getValue(); // Method 2 (returns array) $video_id = $variables['node']->get('field_video_id')->getValue(); // Method 3 if expecting a single value (string) $video_id = $variables['node']->field_video_id->getString(); // Now we can make this available in the TWIG template $variables['video_id'] = $video_id; } } }
Obviously you'd only need to use one of the three methods above.
You might need to play with the output a little but the simple string version should be rendered like: {{ video_id }}
Remember to rebuild the cache or your new code won't be read!