2

I'm a drupal newbie...

When I define css and js at filename.info file, it takes effects for all pages. I have some particular css-js files for some particular pages, and I don't wanna slow site down by importing all these files for the pages actually no need these files.

How can I define js and css for particular pages?

Appreciate helps!!! thanks a lot!!!

2 Answers 2

1

The Drupal API offers two functions drupal_add_css and drupal_add_js that you can use.

There's a gotcha, if you use these in fx the preprocess_page function where the $script and $styles variable already has been created, you need to overwrite it with, drupal_get_css or drupal_get_js

Sign up to request clarification or add additional context in comments.

Comments

0

You can always add specific JavaScript for a particular content type using the preprocess_node function in template.php of your theme:-

function template_preprocess_node(&$vars) {
  if ($vars['type'] == 'content_type') { 
    drupal_add_js(path_to_theme() . '/script.js');
  }
}

Similarly using drupal_add_css for stylesheets.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.