3

I'm adding js and css from a custom module and it works except for the fact that it also adds to the node edit page which I don't want.

I have this in my custom module:

function MYMODULE_preprocess_page(&$vars) {

// Global node.
$node = menu_get_object();
 if (!empty($node) && $node->type == 'my_node_type') {

// do stuff here like add_js, add_css

  }
}

... this works except that it also adds js and css files to the node edit page which I do not want. I've been playing around with this now for a while and any searches I've done have come up blank so I'm out of ideas for now. I suspect I need an extra argument to only add this to a node view and not node edit.

4

You could verify the 3 argument passed inside the menu item (node/%node/edit, node/%node/delete, node/%node/translate). If this third argument is null, you know that it is the node view page.

function MYMODULE_preprocess_page(&$vars) 
{
    // Global node.
    $node = menu_get_object();

    if (!empty($node) && $node->type == 'my_node_type' && arg(2) === null) {
        // do stuff here like add_js, add_css
    }
}
4

A quick, dirty way would be to check the current path for 'edit':

$node = menu_get_object();
if (!empty($node) && $node->type == 'my_node_type' && arg(2) != 'edit') {
  // ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.