Skip to main content
added 300 characters in body
Source Link
sonfd
  • 8.1k
  • 1
  • 20
  • 40

Implement template_preprocess_node in your .theme file and get the page's node with the following code.

/**
 * Implements template_preprocess_node().
 */
my_theme_preprocess_node(&$vars) {
  // This will fire for any node type with the teaser view mode
  if ($vars['view_mode'] == 'teaser')
    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node instanceof \Drupal\node\NodeInterface) {
      // You have the full node object and can access fields as needed.
      // You can even check the $node type in the above if statement to only add
      // this value to the teaser for nodes when you're on the type with your EVA
      // Make sure to add them to the $vars array to see them in your template.
    }
  }
}

See this post re: how to access fields from a node object.

Note: This doesn't do exactly what you're asking, but will work if you're viewing the full page of the node with the EVA.

Implement template_preprocess_node in your .theme file and get the page's node with the following code.

/**
 * Implements template_preprocess_node().
 */
my_theme_preprocess_node(&$vars) {
  // This will fire for any node type with the teaser view mode
  if ($vars['view_mode'] == 'teaser')
    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node instanceof \Drupal\node\NodeInterface) {
      // You have the full node object and can access fields as needed.
      // You can even check the $node type in the above if statement to only add
      // this value to the teaser for nodes when you're on the type with your EVA
      // Make sure to add them to the $vars array to see them in your template.
    }
  }
}

Implement template_preprocess_node in your .theme file and get the page's node with the following code.

/**
 * Implements template_preprocess_node().
 */
my_theme_preprocess_node(&$vars) {
  // This will fire for any node type with the teaser view mode
  if ($vars['view_mode'] == 'teaser')
    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node instanceof \Drupal\node\NodeInterface) {
      // You have the full node object and can access fields as needed.
      // You can even check the $node type in the above if statement to only add
      // this value to the teaser for nodes when you're on the type with your EVA
      // Make sure to add them to the $vars array to see them in your template.
    }
  }
}

See this post re: how to access fields from a node object.

Note: This doesn't do exactly what you're asking, but will work if you're viewing the full page of the node with the EVA.

Source Link
sonfd
  • 8.1k
  • 1
  • 20
  • 40

Implement template_preprocess_node in your .theme file and get the page's node with the following code.

/**
 * Implements template_preprocess_node().
 */
my_theme_preprocess_node(&$vars) {
  // This will fire for any node type with the teaser view mode
  if ($vars['view_mode'] == 'teaser')
    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node instanceof \Drupal\node\NodeInterface) {
      // You have the full node object and can access fields as needed.
      // You can even check the $node type in the above if statement to only add
      // this value to the teaser for nodes when you're on the type with your EVA
      // Make sure to add them to the $vars array to see them in your template.
    }
  }
}