I am trying to get a preprocess function to work on my drupal 7 site and am having some difficulty. I was given this.
function fource_preprocess_page(&$vars) {
if ($vars['is_home']) {
$path = drupal_get_path('themes', 'fource');
drupal_add_js($path . 'js/image_scale.js');
$vars['scripts'] = drupal_get_js();
}
}
-fource is the name of my theme
-I am using the page–home.tpl file as I am using panels for the homepage
? Not sure about the path… (‘themes’, ‘fource’)
? Also need to add the css file.
I have no idea what I’m doing here so the most detailed explanation would be greatly appreciated.
I think in Drupal 7 you actually want to do this in
theme_preprocess_html(). In your theme’stemplate.phpfile you’ll need something like this:The call to
drupal_get_path('theme','fource')just asks Drupal for the full path to your theme, then you just tack your JS file name on the end.To be honest, I’m not sure about
is_homevs.is_front, but Google probably knows.There’s also a function
drupal_add_css(documented here).