Overriding the Default Styling
Three approaches we can adopt to override templates in Drupal 7 Themes
- Overriding templates
- Overriding functions
- Converting themable functions into new template
Theme Registry Plays a vital role while playing around with above three approaches. It provides the Drupal with a cached registry of information on the available functions and templates in theme, when we do any changes in templates or override and theme function or we have created a template we are required to clean the theme registry otherwise drupal wont show you the changes you have made.
Clean Theme Registry
- Go to the Configuration Manager
- Visit the Performance page
- Select the option Clear cached data.
- OR, download the Devel module enable it, it will provide you on the very left hand side a HUT icon under which you will get an option Flush all cache that's it click it and you are done with `clean theme registry`.
Lets Start with
Overriding templates
Steps to Overriding templates
- Create a duplicate template of one of the default template files and then place it in the active theme's directory
- New files will now be called instead of Drupal default file, Drupal will always display the template in the active directory rather than the default template.
- Do some custom changes to the code in the new template file
- Save the file
- Now Clear the Theme Register By following the above mentioned steps
For example . The page.tpl.php file is solely responsible for the results that appear on the html pages in browser, Basically it defines the overall layout of a page of the site.
Now what if you want
To customize the user pages, By default Drupal will use the page.tpl.php file. and if we want a custom page to be displayed, we will need to create a new template named page--user.tpl.php and place it in the active theme's directory. Now, when a user clicks on the My account link, the system will display the file page--user.tpl.php rather than the Drupal default page.tpl.php file.
Best Resource to understand is here About overriding themable output
Please visit related Theming Blogs
Overriding the Default Styling
Overriding Theme functions
Converting Themeable functoin to templates
Thanks
0 Comment(s)