I would like to add a css file when editing content of the content type invoice.

The link is something like this: node/121/edit . I've tried it with it with preprocess_node like this:

function themename_preprocess_node(&$variables) {
    $node = $variables['node'];
    if($node->type == 'invoice')
        drupal_add_css(drupal_get_path('theme', 'themename') . "/css/add.css", array('weight' => 1003));

But he doesn't add the css file. When I do a die; in the if structure he executes it...


You're targeting the incorrect preprocess function. By the time preprocess_node is run all our JS and CSS has been included in the top of our html document already.

Use this function instead:


  • But I can't figure out which node type I'm editing with the preprocess_html function ..
    – nielsv
    May 21 '14 at 14:20
  • I'm pretty sure this is wrong - templates work outside-in. drupal_add_css() in a node preprocess hook has always worked for me. Ironically, using drupal_add_css in template_preprocess_html, definitely won't work.
    – Clive
    May 21 '14 at 14:42

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.