Как более определенное взятие по этому вопросу:
drupal jQuery 1.4 на определенных страницах
Как я проверяю в модуле, является ли узел определенным типом, чтобы смочь сделать определенные вещи к узлу.
Спасибо
Контекст:
Я пытаюсь адаптировать этот код так, чтобы вместо того, чтобы работать над 'my_page' он работал над типом узла.
function MYMODULE_preprocess_page(&$variables, $arg = 'my_page', $delta=0) {
// I needed a one hit wonder. Can be altered to use function arguments
// to increase it's flexibility.
if(arg($delta) == $arg) {
$scripts = drupal_add_js();
$css = drupal_add_css();
// Only do this for pages that have JavaScript on them.
if (!empty($variables['scripts'])) {
$path = drupal_get_path('module', 'admin_menu');
unset($scripts['module'][$path . '/admin_menu.js']);
$variables['scripts'] = drupal_get_js('header', $scripts);
}
// Similar process for CSS but there are 2 Css realted variables.
// $variables['css'] and $variables['styles'] are both used.
if (!empty($variables['css'])) {
$path = drupal_get_path('module', 'admin_menu');
unset($css['all']['module'][$path . '/admin_menu.css']);
unset($css['all']['module'][$path . '/admin_menu.color.css']);
$variables['styles'] = drupal_get_css($css);
}
}
}
Спасибо.
Внутри модуля вы можете сделать следующее:
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) != 'edit') {
if (!($node)) {
$node = node_load(arg(1));
}
if ($node->type == 'page') {
// some code here
}
}
Это загрузит объект узла с учетом текущей страницы узла (если она недоступна). Поскольку я не знаю контекста кода, с которым вы работаете, это довольно грубый пример, но вы всегда можете увидеть свойства узла, выполнив node_load (node_id). Но, в зависимости от функции API Drupal, она может быть уже загружена для вас.
Например, hook_nodeapi.
http://api.drupal.org/api/function/hook_nodeapi
Вы можете сделать:
function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'view':
// some code here
}
}
Попробуйте это:-
function MyModule_preprocess_node(&$vars) {
if ($vars['type'] == 'this_type') {
// do some stuff
}
}