1

I installed bootstrap framework for drupal and copied the sub-theme into my themes directory, renamed all the files accordingly and everything works fine, however any php code that i put in my sub-theme template.php file is not having any effect.

I tried adding google fonts, css files and some other functions to template.php but nothing works, even tho the code is valid.

I wonder what am i doing wrong? Should i be editing base theme template.php file, even tho it will get updated and deleted? Or is there some other reason why my sub-themes template.php has no effect?

1
  • Active theme's template.php always runs, as well as the active theme's base theme's template.php. However the active theme's template.php should be overriding base theme's template.php. Your case is not a default behavior, so it's probably something local to your instance of Drupal, whether it be a combination of either a module, a particular theme or custom code that you've written.
    – Beebee
    Commented Mar 13, 2015 at 16:31

2 Answers 2

1

If you change in template.php then you have to clear the theme cache. Because the contents of the this file is cached in the database, so altering it will not be noticed by Drupal.

You can clear cache from here

Drupal 7: Administration > Configuration > Development > Performance (admin/config/development/performance)

For more information visit Clearing the theme cache

2
  • I cleared all caches after doing updates to template.php. I wonder if clearing theme cache is different from clearing all caches?
    – risha riss
    Commented May 25, 2014 at 10:51
  • drupal_flush_all_caches()
    – Beebee
    Commented Mar 13, 2015 at 16:35
1

Don't edit the files in the bootstrap base theme - they will get overwritten when you update to a new version just as you said. Only edit and add files to the subtheme.

About the changes not showing up: Is it possible that you are using the wrong theme hooks or no hooks at all? Just using functions like drupal_add_css() or drupal_add_js() wont work in the template.php unless you call them from a theming hook like template_preprocess_page().

Here is a good tutorial to preprocess functions: Implementing Preprocess and Process Hooks

If you want to generally add a css file to theme (not just to certain templates as you could with the preprocess functions) however, I would suggest adding them in the .info file of your subtheme:

#original bootstrap css files in your subtheme
stylesheets[all][] = css/style.css
stylesheets[all][] = css/jquery.cover.css

#custom sheet
stylesheets[all][] = css/YOURCSS.css

If you intend to use the less files bootstrap ships with hwever, there is no need to even do that: The bootstap subtheme supplies you with a number of less files you can compile into css for your theme using a programm such as crunch. The file you have to compile is the style.less file, which references all other less files. The output is a single style.css file, the one references above. You can either use the less files the subtheme provides or add new ones.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.