I often wind up doing CSS theming based on node specific rules.
Would love to future (migration) proof this site and node specific theming.

Promise this is a real use case I've recently dealt with.

Comments

austintnacious’s picture

I'll second the desire to optionally add the UUID to node body classes.

There are so many times when you need to select a specific page, term, whatever to apply styles to.
This would be a great feature!

neochief’s picture

Status: Active » Fixed

Unless you want to turn your css files into nightmare, this would be pretty bad idea. Instead, add process this in templates and put the human-readable classes into template.

doublejosh’s picture

It's true that placing a non-human readable class like this is not awesome.
It's also true that it will be bloating in terms of size within CSS files.
Suppose there are CSS and Code Per Node.

However,
-- When styles are truly node-page specific, using a UUID is actually the best way to reference them... for migration and environment.
-- Human readable classes from the node would need to rely on URL, title, nid, etc... all of which are what I'm trying to get away from.

Since writing this I have employed a node specific CSS include technique.

function MYTHEME_preprocess_node(&$vars, $hook) {
  drupal_add_css(
    path_to_theme() .'/css/nodes/nid-'. $vars['node']->nid .'.css',
    $type = 'theme', $media = 'all', $preprocess = FALSE
  );
}

This certainly could be used via UUID and certainly moved out of the theme.

So perhaps the thread could change to: Add Candidate Node UUID CSS File.

Code would be more like this (added a date indicator to respect file age for caching).

function uuid_preprocess_node(&$vars) {
  $file = path_to_theme() .'/css/nodes/'. $vars['node']->uuid .'.css';
  if (file_exists($file)) {
    $age = date("U", filemtime($file));
    drupal_add_css($file.'?v='.$age , 'theme', 'all', FALSE);
  }
}

This does actively improve front-end performance by removing page specific code from general CSS files.
Guessing though that approach is adequately outside UUID's scope.

Still assume that a "UUID in body classes" checkbox would be useful for some folks.

doublejosh’s picture

Posted the candidate CSS file thing in Code Per Node #1441732: Node specific CSS candidate from theme

I guess the CSS body class idea was deemed too ugly.

doublejosh’s picture

Status: Fixed » Closed (won't fix)