If content type with specific field that is not empty has specific taxonomy term attach library I would like to attach a specific library using a taxonomy term to a content type with a specific field that is not empty. The following is not working:

function lehigh_preprocess_page(&amp;$variables) {
// Via taxonomy term: If the landing page is a node and has taxonomy 
via a field named field_taxonomy
$current_route = \Drupal::routeMatch();
$node = $current_route-&gt;getParameter('node');
$target_taxonomy_id = 123;
   if ($node-&gt;getType() === 'standard_content_page') &amp;&amp; $node-&gt;hasField('field_section') &amp;&amp; !$node-&gt;get('field_section')-&gt;isEmpty()) {
     if ($node-&gt;get('field_section')-&gt;referencedEntities()[0]-&gt;id() == $target_taxonomy_id) {
     $variables['#attached']['library'][] = 'lehigh/financialaid';
}
}
}
Try the following , and don't forget to clear the cache 

function lehigh_preprocess_page(&amp;$variables) {
    $current_route = \Drupal::routeMatch();
    $node = $current_route-&gt;getParameter('node');
    $target_taxonomy_id = 123;
    if (isset($node) &amp;&amp; $node-&gt;getType() == 'standard_content_page' 
        &amp;&amp; $node-&gt;hasField('field_section') 
        &amp;&amp; !$node-&gt;get('field_section')-&gt;isEmpty()) {
        if ($node-&gt;get('field_section')-&gt;referencedEntities()[0]-&gt;id() == $target_taxonomy_id) {
            $variables['#attached']['library'][] = 'lehigh/financialaid';
        }
    }
}