By awasson on
Hi there,
I am modifying a site I launched a few months ago so that it can have a new cck content type.
The new pages are going to be fairly plain compared to the rest of the site so I figured I would make a new template like page-plain.tpl.php and switch to it if the content type matched my new cck type.
Make sense so far?
Now what I'm trying to figure out is what I can use as a hook to detect my new content type. The machine readable name is "video_clip".
I'm using the following to switch templates for my home page:
if ($is_front) {
include('page-front.tpl.php');
return;
}
Is there something similar I can use to detect my CCK content types?
Thanks,
Andrew
Comments
I'm fairely new with CCK
I'm fairely new with CCK also, (just downloaded the module this morning) so I'm probably completely off. I know you can do that exact thing with CCK node types so I would assume you could do the same for pages.
For example if you have a CCK Node type called "article" and wanted to have a unique template just for it. You would create a file in with all your other templates called "node-article.tpl.php". That template would then be used autimatically for all nodes with the CCK type of 'article'.
So if your CCK page type were called 'video_clip', you could probably just make a template called, 'page-video_clip.tpl.php' and it would autimatically work.
Thanks it works with a little help
Thanks TPerkins,
With a little help from PhilK (below) it all came together.
I made a template called: page-video_clip.tpl.php
It won't work all by itself. You have to add a little code to the top of your page.tpl.php page:
if ($node->type == 'video_clip') {
include ('page-video_clip.tpl.php');
return;
}
Cheers,
Andrew
node->type
You can use the
$node->typevariable to switch page layouts in the same way as you did with the$is_frontvariable.Example:
<?php if ($node->type == 'content_news') {include ('page-news.tpl.php');return;}?>Recommend you check out Dublin Drupallers phptemplate snippets section of the handbook:
Drupal Handbooks » Customization and theming » PHPTemplate Theme Snippets » Customising full page layouts and sections » Customising the full page layout and sections based on node type
There's a bundle of brilliant snippets in there. Well worth bookmarking for future reference.
Phil.
Thanks PhilK, That did it!
Thanks PhilK,
That did it! Works like a charm.
Great link to full page editing by the way. I've got it bookmarked now. I don't know how I overlooked that.
Cheers,
Andrew
More portable solution.
Put this code at the top of your page.tpl.php. Read the comment in the code to see what it does.
I've also similar setup and
I've also similar setup and I use following names for files which automatically gets accessed without including anything in page.tpl.php
E.g. page-node-123.tpl.php
If I remove this file then by default page-tpl.php is used.
Isn't also a correct way?
Cheers
Dave
It should be...
It should be according to all tutorials and screencasts I have seen on templating. But that simple rule didn't work with me while trying to theme OG pages on my setup. (Guess you are a lucky one.)
The above code, fortunately solved this problem for now...
Thank you, j0rd!
I was unable to get Drupal to recognize some pages I created with CCK until I tried this solution. This works great with Drupal 6 and it's so concise!
wrong question?
well, the nice users gave their advice to fix the problem you posted. I guess if you wanted to ask
"how to override the node.tpl.php" Because my friend, the CCK is linked to the node, not the page.
that said, just copy
node.tpl.php
to
node-machine_name_of_contentype.tlp.php
modify and enjoy.
NOTE: overriding the tpl usually means we are doing something wrong.