Skip to main content
Tweeted twitter.com/StackDrupal/status/858216236324466688
added 4 characters in body
Source Link
Chris Happy
  • 1.9k
  • 16
  • 31

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'];  
  }

}

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'];  
  }

}

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

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

}
added 475 characters in body
Source Link
Chris Happy
  • 1.9k
  • 16
  • 31

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'];  
  }

}

I'm trying to get run some code if the content type of the current page is equal to events.

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.

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'];  
  }

}
Source Link
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.

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.