Drupal 8 - Get node value in your THEME_preprocess_node()

By xngo on March 7, 2019

In your ./themes/YOURTHEME/YOURTHEME.theme file, add the following:

/**
 * Replace YOURTHEME with the actual name of your theme and 
 *   field_NAME_OF_YOUR_FIELD with the actual machine name of your field. 
 */
function YOURTHEME_preprocess_views_view_field(&$variables) {
 
    if (($node = \Drupal::routeMatch()->getParameter('node')) && 
                    $node instanceof \Drupal\node\NodeInterface) {
 
        print_r($node->field_NAME_OF_YOUR_FIELD->value);
    }
}

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.