0

I want to add a body class that will only appear on the actual node display (e.g. mysite.com/node/1). I don't want this body class to appear on the node/edit page (e.g. (mysite.com/node/1/edit) or the node/add page.

The reason for this is that I am making custom node form templates. At the moment, the css gets wrongly applied to the node Display.

I know I could just add a wrapper DIV to my templates, but I would rather use the body class, as it will be more efficient for my theming work flow.

I have successfully applied body classes to the edit and add displays with the following code in template.php

function MYTHEME_preprocess_html(&$variables) {
  if ((arg(0)=='node' && arg(2)=='edit') || (arg(0) == 'node') && (arg(1) == 'add')) {
    $variables['classes_array'][] = 'node-edit-page';
  }
}

Is there something similar I could use to target the actual node display? I tried doing a KPR dump of the page, node and HTML hooks with theme_devel, but I could not find anything useful.

1 Answer 1

1

arg(2) will return NULL on node pages (like node/1).

  if (arg(0)=='node' && is_numeric(arg(1)) && !arg(2)) {
    $variables['classes_array'][] = 'node-view-page';
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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