Hello
A while back I migrated most of my purely XHTML, JavaScript and CSS site to Drupal. Some of the remaining pages use custom scripts and styles to create specific results on individual pages. I'd like this functionality to be carried over but unless I'm missing something this is harder than it seems.
I've seen a lot of posts by others with similar problems, and most remain with zero responses. My guess is it isn't that easy. Per theme, yes. Per section, yes (with some fiddling). Per node? Hmmmm.
What I have sussed is I have a couple of options:
1 - Include the required code in the template. Then it's loaded on every page despite only being needed for one, not very efficient.
2 - Do some jiggery-pokery with PHP. I'll be honest, I suck at PHP and the prospect of learning to suck less doesn't fit in with the time I have available. Stuff like this scares me: http://drupal.org/node/319895. Plus having to mess with the code every time I create a node needing unique content totally kills the point of using a CMS in the first place.
What I really need is just a field on the create node page where I can specify the names of the JS and CSS files I want loaded for that node alone. Alternatively is there a line of code I can put in the article that will add the proper
and
Comments
Drupal_add_js
Worth a look... drupal_add_js and drupal_add_css
http://api.drupal.org/api/function/drupal_add_js
Good luck. Please post back here with your outcome.
DJ
I've done this by adding
I've done this by adding code into the page preprocess function in template.php (Drupal 6). If you just want it for a node it should be fairly easy. Something like this:
function phptemplate_preprocess_page(&$variables) {
// Drupal "Theme Preprocess" see http://drupal.org/node/223430
// Drupal "Template Suggestions" see http://drupal.org/node/223440
switch ($variables['node']->type) {
case 'mytype':
$css_values = array_shift($variables['css_file']); // CCK text field will be $variables[][0]['value'] - assume CCK field is css_file here
$css_file = $css_values['value'];
break;
global $theme_path;
$css = sprintf('/%s/%s',$theme_path,$css_file);
drupal_add_css($css,'theme','all',false);
}
... maybe solved...
CSS Injector
there's also css_injector
http://drupal.org/project/css_injector