I know this is a loaded question and pardon my ignorance but I would like to know how or why it would benefit me to use these functions?

Thank you

Comments

nevets’s picture

One would use require_once to load other PHP files.

drupal_add_css is used to add additional css files, while drupal_add_js is used to add additional javascript files. drupal_add_js also makes sure jquery.js is loaded if other javascript files are added. Bot drupal_add_css and drupal_add_js require a path to the file and drupal_get_path is often used to get the current base path (either based on module or theme)

Anonymous’s picture

What if I keep my JS files in /sites/all/libraries folder? Then I cant use drupal_get_path?

Anonymous’s picture

require once and including js, css. they are not relevant

nevets’s picture

In that case you would want to use the Libraries API.

pkej’s picture

By using the drupal hooks you make sure that your files are served through the same system. The advantage is that modules that cache, compress, aggregate or tidy the output has access to your files of the type as well. This is very important when it comes to site optimisations. Generally you want to serve one css file, one jss file, to limit the number of requests from the user agent (and thus making the user experience better).

Paul K Egell-Johnsen

dillonm’s picture

I think khoasx is hinting at the same thing: require_once is for including other php files *in* a php file - which are then evaluated by the php parser.

Using drupal_add_css and drupal_add_js are for include the css and js files, which are not evaluated by the php parser and are evaluated by the browser as css and js.

drupal_get_path is also different. It just gets a folder path.

Maybe you could elaborate on your question a little?