Last active
February 17, 2021 03:38
-
-
Save frankyonnetti/5944774 to your computer and use it in GitHub Desktop.
Drupal - if content type in views block tpl or node #drupal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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