1

I am building a website using Drupal 7, Views, Rules, Ctools, Panels, etc.

I need to change the content color based on the date. The idea is that each quarter's reports have a different color to make them easier to sort over the life of the student.

Any ideas on how to achieve this?

1
  • do you mean for a node, block, view - background colour, font colour, title colour?
    – Geoff
    Commented May 7, 2015 at 18:17

2 Answers 2

0

In your theme, you can implement hook_preprocess_page(&$variables) were you can retrieve the currently displayed content (if any) as $variables['node']. From there, you can retrieve the value of a date field using field_get_items() and use that value to assign classes to the <body> of the page in $variables['classes_array'].

function THEME_preprocess_page(&$variables) {
  if (($node = $variables['node']) && ($node->type == 'report')) {
    if ($items = field_get_items('node', $node, 'field_report_date')) {
      $variables['classes_array'][] = drupal_clean_css_identifier('report-month-' . format_date($items[0], 'custom', 'F'));
    }
  }
}
0

Maybe consider the ThemeKey module? From its project page (bold markup added here):

... allows you to define simple or sophisticated theme-switching rules which allow automatic selection of a theme depending on current path, taxonomy terms, language, node-type, and many, many other properties.

In combination with Drupal's theme inheritance you can easily achieve features like:

  • a date/time-selected Christmas theme
  • ...

So by using like 1 theme variation for each quarter you could get the job done, no?

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.