Hi I have some css / js attached to a box with Code Per Node. CPN creates physical files for the code. In hook_preprocess_node I can see the CPN output, for example:

$vars['cpn']['css'] = token_replace($vars['cpn']['css']);
$vars['cpn']['js'] = token_replace($vars['cpn']['js']);

This successfully replaces the tokens in memory but the physical file is loaded up in the header and so the tokens aren't replaced in there and cause an error. Any ideas?



Both drupal_add_js and drupal_add_css have an option to add code "inline". You can try his in a template_preprocess_node:

function mytheme_proprocess_node (&$variables)
  drupal_add_js($variables['cpn']['js'], 'inline');
  drupal_add_css($variables['cpn']['css'], 'inline');

If you do this in a theme, then the CPN hook should have already been fired. If you do it from a module, you may need to play with the module weights to get yours to follow.

| improve this answer | |

Ok at the time of posting this there is no clean solution. You could pass all the cpn code inline but it isn't as easy as $vars['cpn']['js'] because this is only the CPN for the node and the CPN for any blocks/boxes on the page is elsewhere. This could get messy and you would have to intercept any CPN js/css that would have normally been added to the page in hook_js_alter by removing anything coming from the custom cpn path - messy.

For now (not advised) you can edit the CPNs .module:

  • Find function cpn_save_file($data, $filename) and add: if(function_exists('token_replace') $data = token_replace($data);
| improve this answer | |

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.