Add inline styles/JS from fields to My site contains nodes which require different styles (and the occasional inline JS script) and the ability to adjust these styles through the interface rather than via code. These styles are currently implemented via a Code-only text field using &lt;style&gt; tags, which is not ideal. However for systemic reasons I can't place these node-specific styles in individual libraries. 

How can I extract the contents of specific code-only fields and reposition this content as inline styles in the &lt;head&gt; of the page? I understand that this is not the preferred Drupal way, however I need a solution.
You could do this with a preprocess function. The code here works for full views only (it won't work e.g. in a view of multiple teaser nodes).

function THEME_preprocess_html(array &amp;$variables) {
  $router = \Drupal::routeMatch();
  $node = $router-&gt;getParameter('node');
  if (is_numeric($node)) {
    $node = \Drupal\node\Entity\Node::load($node);
  }
  if ($node instanceof \Drupal\node\NodeInterface) {
    $variables['node_object'] = $node;
  }
}


Now you can use {{ node_object }} in your html.twig.twig, e.g.:

&lt;html&gt;
&lt;head&gt;
  {% if node_object %}
    {% if not node_object.field_css.isEmpty %}
      &lt;style&gt;
        {{ node_object.field_css.value|raw }}
      &lt;/style&gt;
    {% endif %}
    {% if not node_object.field_js.isEmpty %}
      &lt;script&gt;
        {{ node_object.field_js.value|raw }}
      &lt;/script&gt;
    {% endif %}
  {% endif %}
  ...


And yes... don't try this at home kids ;-P