node.tpl.php overrides

Events happening in the community are now at Drupal community events on www.drupal.org.
sharkmeat's picture

I'm having trouble trying to get template file overrides to work.

I have created node-playlist.tpl.php which refers to a content type called "playlist" created in CCK and placed it in my Zen sub-theme folder. However, nothing I put in this file is displayed for that particular content type and the regular node.tpl.php is used. Am I missing something here or is it just not possible with a sub-theme? I have theme registry rebuild enabled!!!

Any suggestions???

Thanks

Comments

Drupal 6.4

sharkmeat's picture

I forgot to mention using Drupal 6.4

node.tpl.php also needs to be in subtheme

sharkmeat's picture

OK I worked it out. If the node.tpl.php file from zen is not copied into the sub-theme then the content type variants i.e. node-[content-type].tpl.php are not seen. Once the node.tpl.php was copied to the sub theme then all was good.

I am trying to do the same thing

nanatulip's picture

Sharkmeat,
Could you please tell me in more detail what you did to make your CCK use the different node.tpl.php? I understand that I need to copy the node.tpl.php from the zen folder & put it in my sub-theme folder which is named foo. (Also, I know this is probably a dumb question, but what does foo stand for?)

Then, my CCK content type file name is member-hp... so I am supposed to create another file called node-member-hp.tpl.php?????????????? Or am I supposed to rename the node.tpl.php??????????

I am lost. Can you please help?
Tami

Tami

You weren't actually

Garrett Albright's picture

You weren't actually supposed to name your subtheme's directory "foo"… that was just a placeholder name in the documentation…

Anyway, you should copy over node.tpl.php from the "zen" directory into your theme's directory. Then copy the file inside your theme's directory and rename it to node-[type].tpl.php - only don't actually use [type]; replace the [type] part with the machine name of your node type. So node-member-hp.tpl.php in your case (or should it be node-member_hp.tpl.php? You might need to try both). So you should have both an unadulterated node.tpl.php and node-[type].tpl.php in your subtheme directory - if you just have node-[type].tpl.php, it won't work.

I did as you said

nanatulip's picture

As I said, "I am sure this is a dumb question." Ha Ha. I guess it is obvious now that I did not take computer science in college.

Anyway, I copied the node.tpl.php from the "zen" directory & pasted into my "foo" directory. Then I copied the node.tpl.php file and pasted into my directory again with the name of node-member-hp.tpl.php. Both files (node.tpl.php & node-member-hp.tpl.php) are in my "foo" directory. (By the way, when I go to Administrator - Content-types, my Member Home Page type says member_hp, but when I fire up the Firebug, it says . So I am not sure if it should be member_hp or member-hp, but I have tried them both as you suggested.)

Anyway, what else is necessary to link the Member Home Page to that tpl.php? Do I need to do something in the .info file, or in a css file? I did copy the foo.css and rename it to member_hp.css & member-hp.css to see if that was what was missing, but it still didn't work.

I know you may think that I am a hopeless case, but considering I have gotten this far with NO WEB DESIGN training what so ever, it is not impossible for me to understand. Please help.

Tami

Tami

The foo.css file should be

Garrett Albright's picture

The foo.css file should be named the same as your theme (the same as your theme's directory), so if it's still foo, keep it as foo.css for now.

Just renaming the node-[type].tpl.php file should suffice, but make sure you have the "Rebuild theme registry on every page" option enabled on the theme configuration page for your theme, or it won't show up instantly. Also, I suggest downloading the Devel module and enabling its "Theme Developer" feature. By experimenting with it a little, you should be able to figure out exactly which files Drupal is looking for as it renders any part of your site - it can be incredibly handy for those trying to learn how Drupal's theming system works.

And don't beat yourself up for not being a CS major - I graduated with a BA in English literature. But I had to get a job as a programmer because I really like those "sleeping indoors" and "proper basic nutrition" ideas.

I got the member_hp file to use my tpl.php file

nanatulip's picture

Using the devel module, I can see that my node is now using the new file instead.

This file is full of php stuff that I know NOTHING about. Is it possible to get this file working with it's own .css file that I know MORE about?

If so, how? I already copied my subtheme.css file & renamed it node-member_hp.css to see if that would work & it did not.

Tami

Tami

Your subtheme.css file

Garrett Albright's picture

Your subtheme.css file (foo.css or whatever) is editable. Open up that puppy and go to work.

If you'd rather start with a blank CSS file, create one in your subtheme directory, then edit the subtheme's .info file to include that new CSS file. The line you'll want to add will look something like stylesheets[all][] = new-stylesheet.css.

If you want to apply styles to just one node type, you can do that easy enough with just some careful targeting. Note that the <body> tag gets a class of node-type-[type] when you're looking at a node. So to affect <p> blocks only on nodes of type member_hp, the CSS will look something like

body.node-type-member_hp p {
  background-color: purple;
}

If all you need to do is change the CSS of your subtheme, then node-[type].tpl.css templates are not necessary.

You have been such a help

nanatulip's picture

I appreciate the patience you have had & the help you have given. It is difficult to find someone on this website that can speak my "un-computer-science" language. Mostly everyone here expects everyone else here to be web-designer literate.

I am at work now, but I will try your suggestion tonight when I get home. I knew that the foo.css was editable & I have changed it for my home page, but I have tried changing it for my nodes, but it interfered with my home page. That is why I thought I would have to create another tpl.php file. I guess I just wasn't using the command node-type-member_hp.

If I could bother you just a little bit more, I would be eternally greatful. On my member_hp pages (which is Member Home Page) I have an input field where the member can upload a video to me. This upload goes into my database & I download it, re-format it to an flv file (so it can be viewed on the web) & store it in a file that I have named flv/%uid. Do you know how I can link this file back to the member so that it can be shown on the Member's Home Page?

Thanks again,
Tami

Tami

Tami

The answer to that will

Garrett Albright's picture

The answer to that will probably depend largely on how your site is built - how the videos are stored on your site, and how things appear on a member's home page. But I'll take a wild guess anyway - If the video is associated with a node somehow, you could make that user the author of the node. When editing it, open up the "Authoring information" fieldset and enter the user's username in the "Authored by" field.

Sometimes one is tired after too many hours of drupal

Liaz's picture

... and forget the basics such as:
"So you should have both an unadulterated node.tpl.php and node-[type].tpl.php in your subtheme directory - if you just have node-[type].tpl.php, it won't work."

It was great to find this answer so quick.
Thanks :)

Thanks :)

Evariste-1's picture

I had the exact same problem. Thanks for posting how you got it to work!

Thanks, I too had the exact

danomanion's picture

Thanks, I too had the exact same problem.

The little things.

thank you ! same happened to

hedac's picture

thank you !
same happened to me

Thanks

japo32's picture

Thanks very much. This solved my problem.

At drupal 7 it must be

erlendoos's picture

At drupal 7 it must be node--page.tpl.php btw.

(for page override)

erlendoos's picture

(for page override)

I'm working on a custom theme

ahcolus's picture

I'm working on a custom theme in D7, but the node.tpl.php is not used at all, the modification in it are ignored. I created a 'templates' directory in the root template directory, the html.tpl.php and page.tpl.php are in there and work as expected but node.tpl.php is ignored. Any suggestion? Thanks to all in advance.

Zen Task Force

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week