Skip to content

Instantly share code, notes, and snippets.

@frankyonnetti
Last active February 17, 2021 03:38
Show Gist options
  • Select an option

  • Save frankyonnetti/5944774 to your computer and use it in GitHub Desktop.

Select an option

Save frankyonnetti/5944774 to your computer and use it in GitHub Desktop.
Drupal - if content type in views block tpl or node #drupal
<?php //set var to identify content type
$node_type = $row->_field_data['nid']['entity']->type;
?>
<?php //check for content types
if ($node_type == 'CT_NAME' || $node_type == 'CT_NAME_OTHER'):
?>
Do something...
<?php endif; ?>
<?php //check for node id
if ($node->nid == 39):
?>
Do something...
<?php endif; ?>
/*
* http://drupal.stackexchange.com/questions/12725/attach-a-script-to-a-particular-node-id-or-view
*/
<?php
// Node ID:
function THEMENAME_preprocess_node(&$variables) {
if ($variables['nid'] == 'INSERT_NODE_ID') {
// include javascript
drupal_add_js(path_to_theme() . 'INSERT_SCRIPT');
}
}
// View:
function THEMENAME_preprocess_views_view(&$variables){
if ($variables['name'] == 'INSERT_VIEW_MACHINE_NAME') {
// include javascript
drupal_add_js(path_to_theme() . 'INSERT_SCRIPT');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment