I installed the Node Class module. I have a view, where the node class should be imported into the title field of the view.

How can I achieve this?


As far as I understand, you want to add a class name to the title field of your nodes listed in a view. (1) Views provide this functionality by default:


Adds the class to the selected html element, <span> is by default. It can be used as a field wrapper.

(2) In case this is not suitable for you, you may very well use view's "rewrite results" :


It can be used to wrap the field's text.

(3) Lastly there is always the preprocess_views_view_fields solution where you can edit your field's attributes:

if($view->name == 'view-name') {
  $vars['fields']['title']->wrapper_prefix = '<div class="views-field views-field-title my-class">';

It can be used as a field wrapper.

| improve this answer | |
  • The thing is, for each node the used class may be different, or some times no class may be used. in that case, how it will update dynamically for each node titles in the views. what i actually want is, I need to highlight some entries highlighted in a calendar view. for that, i planned to use dynamic class – Jaseer Kinangattil Jan 15 '16 at 11:00
  • @JaseerKinangattil, this is far far away from your original question...However the (3) case will meet your needs. Place all your logic in that hook. You must have some logic that decides when to add a class or not. If that logic is based on the field of the node_class module, you can node_load the node you like (use this $view->result[0]->nid) and retrieve any class from there. Then add any class or leave blank to/the wrapper_prefix – mchar Jan 15 '16 at 17:27

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.