When working with large websites and web-applications the number of files on your theme folder can grow quickly, and if you're not organized it can get very messy . As a result you’ll find yourself spending a lot more time looking for bits of code every time you have to change or update something.
Here are some tips to help keep you organized.
File Structure:
On Drupal a couple of files have to be on your theme rood folder:
- - page.tpl.php
- - node.tpl.php
- - template.php
- - themename.info
- - comment.tpl.php
If your file doesn't have to be on the theme root folder, it should be organized with similar files on subfolders. Here is what we typically use:
- - css (folder)
- - js (folder)
- - flash (folder)
- - images (folder)
- - templates (folder)
- - views (folder)
Naming Conventions:
When naming your TPLs alway be very descriptive and try to group files that theme similar items together. For example, all forms should be form_nameoftheform.tpl.php and all blocks should be block_nameoftheblock.tpl.php
Similar convention can be used for images. icon_nameoftheicon.gif, background_areawhereyouuseit.jpg, header_nameoftheheader.png etc.
Note that I always use the underscore ( _ ) instead of a dash ( - ) on my filenames. Whichever you choose to use just keep it consistent.
CSS :
It is probably a good idea to have multiple style sheets divided according to each section of the site they belong. This will not only help keep you organized, but it will increase the speed on the page load. Eg: you don’t have to load the user profile css on every page if you wont be using it.
page.tpl :
If you have to add javascript or CSS to every page on your site, you should do it on the Info file
If you see yourself writing a long code to something specific like a navigation, or a footer, you should have that code on a separate template file.
These were some very simple things any themer, beginner or advanced, can do to help save a lot of time in the long run.
Do you have your own style of staying organized? Share some tips with us!
Have a happy theming!
Erico Nascimento

Comments
@ Drupal Theme Garden
The views folder is a personal preference. You could have your views template files with the other templates but I find it easier to have them on a separate folder so I know exactly where to go when I'm theming a view.
@peach - all drupal themes
thanks for the tip. I'll make the correction on the post.
Here's a helpful little tip, the only files that are required in the theme's root is the .info file and template.php. This is cool because you can put all your .tpl.php files in a templates/ directory and Drupal will still discover them.
@Helior Colorado
Thanks for that. Will try to implement the new organization and group my node and page tpls on my next project.
Another thing I do is create a folder of the each views within the views directory.
If I have created a views called "blog" I create a folder called with in the views directory called blog and place the templates in that folder (views/blog).
A lot easier to find views templates that way.
Thanks for this post.
But I don't understand "views (folder)"? Can you be more descriptive, please?
For a big theme I usually have something like this:
theme
--css
--js (when needed)
--img
--tpl
----blocks
----cck (when needed)
----page (for all page.tpl.phps)
----node (for all node.tpl.php)
----views (for all views templates)
template.php
theme.info
If I only have one or two page and node templates I will throw all of it within the tpl folder. This can always be changed later, just clear your caches and you're done.
And since usually my themes are developed as subthemes of ninesixty and I use admin themes my theme folder looks like this:
sites/all/themes:
frontend (folder)
--ninesixty
--mytheme (subtheme of ninesixty)
backend (folder, example)
--tao
--rubik (subtheme of tao)
I tried putting a node tpl in the "node" folder but my site does not see it. I cleared cache. i put it in sites/mysite.com/themes/theme428/node/node-video.tpl.php.
thanks
I'm very new to the world of developing websites and basic HTML. With that said: if there's one thing I can say that I've learned, it's that I'm horribly disorganized. My files are all over the place and my code had become rather sloppy. Any sort of organizational advice when it comes to Drupal pages (or ANY website for that matter) is always appreciated in my book.
I'll normally go to this site for guidance (I recently bookmarked it):
http://www.lullabot.com/articles/Landing Page Optimization/assembling-pages-with-drupal/
It wasn't anything outrageous, but hey, it got my started. :)
Since usually my themes are developed as subthemes of ninesixty and I use admin themes my theme folder looks like this, only files that are required in the theme's root is the .info file and template.php.
i've created the views folder under mythemes direcory and also put a files as like as views-view.tpl.php.
how its call these file in drupal.
i have to write any piece of code in template.php file.
please help me , how its work
The site isn't reading any of the theme .tpls in subfolders. I kept the required files in the theme root, and I've tried clearing all caches multiple times but nothing seems to work until I take it back out of the subfolder.
Any ideas on why this would be?
@pandikamal: For views there is a naming convention you have to follow and that should do the trick. Check this post: http://www.appnovation.com/theming-views-drupal-6-simple-way it might help.
@William: I've never had that problem What files are you trying to move into a folder? Page.tpl node.tpl? If they are custom theme files there might be a path problem when declaring the tpl.
Cheers!
thanks.
i've created the views template files under views folder and its working fine.
is possible to create the block template files under the block folder.
And one more, pllease help me, how to create a own custom views module in drupal that's based on the slideshow image. is possible?
thanks,
pandikamal
Post new comment