1

I'm trying to add css and js to a view via a preprocess in my template.php.

I've created themename_preprocess_views_view_my_view_name($vars) and added in my drupal_add_js/css but its not working. The view loads fine but the added css and js are not outputted. My drupal_add_js syntax is correct because I've tested it in a hook_nodeapi in a custom module. The documentation is really unclear as to how to use the function with views.

Any help would be greatly appreciated.

2 Answers 2

4

I've had something similar to me happen with styles. I would add stylesheets via the drupal_add_css method in a preprocess function but they would not appear on the page. What I assumed is that the $styles variable was already populated. I resolved by setting $vars['styles'] to drupal_get_css. Example:

drupal_add_css(path_to_theme() . '/css/foo.css','theme','all');
$vars['styles'] = drupal_get_css();

You can try to see if the same thing is happening with your scripts. Example:

drupal_add_js(path_to_theme() . '/js/foo.js');
$vars['scripts'] = drupal_get_js();
Sign up to request clarification or add additional context in comments.

Comments

0

are you sure that your preprocess is being picked up? the naming can be a little funky sometimes. I recommend using the devel themer module from the devel module that allows you to view which theme functions and overrides are being used.

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.