I'm trying to get run some code if the content type of the current page is equal to events
. I am using Drupal 8.
However, I'm unable to write the if statement.
I've tried:
if ($node->type == 'events'){...}
if (Node::getType == 'events'){...}
I also saw this question, but I have no idea how to apply it.
Full code:
// Add og:event:start_date meta tag
function MY_THEME_preprocess_html(&$variables) {
if ($node->getType() == 'events'){
$time = [
'#tag' => 'meta',
'#attributes' => [
'http-equiv' => 'og:event:start_date',
'content' => $node->field_next_time[0]>field_next_time->value,
],
];
$variables['page']['#attached']['html_head'][] = [$time, 'og:event:start_date'];
}
}