Skip to main content
2 of 3
added 475 characters in body
Chris Happy
  • 1.9k
  • 16
  • 31

If Content Type Equals, then

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],
      ],
    ];

    $variables['page']['#attached']['html_head'][] = [$time, 'og:event:start_date'];  
  }

}
Chris Happy
  • 1.9k
  • 16
  • 31