1

I have tried the following code corolla theme's template.php

/**
 * Implements template_preprocess_node().
 */
function corolla_preprocess_node(&$variables) {
  $flag = flag_get_flag('sold'); // Machine name of your flag.
  if ($flag && $flag->is_flagged($variables['node']->nid)) {
    $variables['classes_array'][] = 'node-flag-sold';
  }
}

This is supposed to add CSS class="node-flag-sold" next to "node". But looking through my firebug, there arenosuch classes added.

Please note, that my node--content-type.tpl.php is custom rewritten. Do I need to add anything there?

1 Answer 1

3

The preprocess code looks reasonably correct.

Make sure you're printing out the $classes variable in your custom node--content-type.tpl.php

e.g, in the wrapper div here:

<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>

<!-- Node template content ... --> 

</div><!-- /.node -->

If curious, $variables['classes_array'] is flattened into $variables['classes'] in template_process with

// Flatten out classes.
$variables['classes'] = implode(' ', $variables['classes_array']);

In D7, process functions are introduced, running after preprocess functions.

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.