Hi, I'm wondering if anyone has any tips on how to organise custom page templates in the theme folder. I've been searching around but can't find anything - perhaps I'm searching for the wrong thing?

What I normally do when I create a new template is either name it based on the node, for example page-node-25.tpl.php or give it a custom name like page-customname.tpl.php and then use the Node Page Template Module to assign it a node.

However, after creating alot of templates it starts getting really messy in my theme folder. Is there a way to organise them? Perhaps put them in different folders?

Or is there a better way to assign different templates to different nodes?

Many thanks.

Comments

rbriskie’s picture

Why would you create a page template for each node anyway? Isn't the point of a CMS/templates to elimate the need to manually code each page.

There must be a better way of doing this, maybe setting up some cck fields that have appearance options for the node.

leahtard’s picture

Agree with rbriskie, creating a new node template may not be the most effective way to create different looks for each page. You may want to look into if you can achieve this using Blocks, Panels (http://drupal.org/project/panels) or Context (http://drupal.org/project/context). I am sure if you search Panels and Context (both modules), you will find some resources explaining how they work.

Cheers, Leah

nickytu’s picture

Generally, I put default templates in the templates folder, then within the templates folder, I add "node", "general" (shared templates), and different views folders.

Hope this helps =)

- nicky Tu
Drupalist + Photographer in Vancouver, BC, Canada
Photography: www.flickr.com/photos/nickytu

eatanicecream’s picture

Thanks for your tips guys. I do try to keep the number of template files as low as possible, but often I want particular nodes to look very different so I haven't been able to achieve it with just blocks.

I've not looked into panels, however. I will do.

@nickytu How do you associate the nodes with the different templates if you've put them in different folders?

ericpai’s picture

Can you put block templates in a "blocks" folder? And node templates in a "node" folder?
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

Eric

Jeff Burnz’s picture

Yeah, of course you can, you probably (if using Drupal 6) need the node.tpl.php file in there as well, the root template MUST be in the same directory (in D7 this bug is fixed).

I used to have templates very abstracted, so the directory structure looked like this:

templates
- node
- block
- page
- views
- etc...

But now I just use one big templates folder, this can be good because you can sort alphabetically and they all mostly fall into place for easy scanning.

If I start getting a lot of templates, or perhaps lots of one type of template (like a lot of views templates), then I might make a folder just for them.

ericpai’s picture

Thanks Jeff. I was missing the part that the default templates had to be in there also (page.tpl.php, node.tpl.php, block.tpl.php). Now it all works.

It it possible to have a block template that will work for a few blocks with different names?
I have a few block that were created by Views like: "block-views-ad_view-block_1.tpl.php", "block-views-ad_view-block_2.tpl.php".
Can I create a block template like "block-views-ad_view.tpl.php" and have those 2 blocks use it?

thanks

Eric

Jeff Burnz’s picture

Yes you can, as long as the blocks are created with the same view - add multiple block displays to the same view and then check the theme information, which will tell you all the possible template names - one of them will be at the right "level" and match all blocks in that view.

gotosachin18@gmail.com’s picture

hiiii......i created a file with page-member.tpl.php in site/all/themes. when i m using if(!drupal_is_front_page()){print $content} in this file it gives fatel error
Fatal error: Call to undefined function drupal_is_front_page() in /var/www/drupal_work/sites/all/themes/new/page-member_about.tpl.php on line 108. what should i do? can i make custom region in this file i.e.(page-member.tpl.php)? my page.tpl.php file shows custom region perfectlly.....
plz help me...i m stuck on this problum..plz help me

gotosachin18@gmail.com’s picture

hiiii......i created a file page-member.tpl.php in site/all/themes. when i m using if(!drupal_is_front_page()){print $content} in this file it gives fatel error
Fatal error: Call to undefined function drupal_is_front_page() in /var/www/drupal_work/sites/all/themes/new/page-member.tpl.php on line 108. what should i do? can i make custom region in this file i.e.(page-member.tpl.php)? my page.tpl.php file shows custom region perfectlly.....
plz help me...i m stuck on this problum..plz help me. i m using drupal 6.
can i make region like page.tpl.php in this file(page-member.tpl.php)?