开发者

Drupal 7: How to load js and css files on different pages

开发者 https://www.devze.com 2023-03-09 21:04 出处:网络
What is the best way to load a js a开发者_如何学JAVAnd css file on certain pages (not on every single page like happens when using the .info file)?Drupal provides two functions: drupal_add_css() and d

What is the best way to load a js a开发者_如何学JAVAnd css file on certain pages (not on every single page like happens when using the .info file)?


Drupal provides two functions: drupal_add_css() and drupal_add_js().

You can use these at any point in your code to add a CSS or JS file to the page load.


If the pages contain a form, you can use something similar to the following code:

$form['#attached']['css'] = array(
  drupal_get_path('module', 'ajax_example') . '/ajax_example.css',
);

$form['#attached']['js'] = array(
  drupal_get_path('module', 'ajax_example') . '/ajax_example.js',
);
0

精彩评论

暂无评论...
验证码 换一张
取 消