I came to a solution using a preprocess function. A key/value pair is added to the parent node. Named "headline_level" it is later referenced by the child and +1 is added. That number is assigned to a twig variable as the headline's number, "headline_level" is increased by 1 for the child if itself has children.
In this image we see a parent "office" pulling in child nodes as fields.
Level Diagram
Parent (h1)
|_ Child (h2) (see image)
|_ Grandchild (h3)
|_ Great GrandChild (h4)
Preprocess Function for theme
function THEME_preprocess_HOOK(&$variables) {
$node = $variables['node'];
/**
* Parent Headline Level
* Displays logical headline structure
* Applies higher value to 'headline_level' for subordinate content types; used in '/templates/node--HOOK.html.twig'
*/
if ($node->_referringItem) {
// Variables
$counter = 1; // start level at 1
// Append 'headline_level' to HOOK node
$node->headline_level = $counter;
$parentHeadline = $node->_referringItem->getEntity()->headline_level;
// Check node for $parentHeadline else $counter, set twig variable
if (isset($parentHeadline)) {
// Increase 'headline_level' by 1
++$parentHeadline; // add 1
$node->headline_level = $parentHeadline;
$variables['office_headline_level'] = $parentHeadline;
} else {
$variables['headline_level'] = $counter;
}
}
Twig Template for Content Type
<div>
<h{{ headline_level ?: 2 }}>{{ label }}</h{{ headline_level ?: 2 }}>
{{ content.field_people }}
</div>
As mentioned in the comments, these Offices should have been a Taxonomy. However, they were created as content types and referenced by fields.