2 replies [Last post]
kiwi_steve's picture
Offline
Joined: 01/14/2008
Juice: 131
Was this information Helpful?

I'm trying to write a custom page.tpl.php for a site I am doing (well, copy and cludge, not write - PHP is beyond me at this stage... Smiling (oh, and I have Ubercart installed and will be using that to sell a few small site-related items once all the tricky stuff is done - Ubercart is one of the base modules I always install now Smiling

The development environment is http://ort.essentialtech.co.nz - not sure if the DNS is set up fully yet - I'm using a hosts file entry to force it from my machine - ip is 203.96.89.140 if anyone wants to set it up if its not working... Its a site that I am porting from Joomla (otagorailtrail.co.nz) because a: it's been managed by about 5 different web guys over the years and mangled beyond belief - b: its an old copy of Joomla and I have no idea what will happen should I try to update it - c: I've decided I don't like Joomla all that much - and D: I like Drupal, I know Drupal and Drupal works... and finally, UberCart doesn't install on Joomla Smiling

Ok, so this is a copy of the query I've posted on the Drupal site under the dreamy theme page (I'm using the dreamy theme as a basis, because its laid out the way I want and the code and CSS is not going to need too much tweaking to get it right). Oh, and I'm posting here because I have always got ten times more Drupal help from here than any other Drupal site, including the main one. I know this isn't an Ubercart issue, but I also know there are some bright cookies on here and someone can probably help me Smiling

I've got a content type called Accommodation Listing (machine readable name accommodation_listing). I've copied the page.tpl.php to page-accommodation_listing.php and done a simple proof-of-concept change to it (added some text beside the breadcrumb code), and tested that making the change works on the main page.tpl.php... which it does - the text appears... but not on the accommodation one.

What I can't seem to get to happen is for the accommodation_listing template to do anything. I'm sure I have done this before with the block.tpl.php on the 4wdstuff.co.nz (using a different theme - but I got that custom block going via some help from here), and the reading I have done has lead me to believe I may need a template.php file (the theme doesn't seem to have one - should I create one? What should it have in it if thats the case?)

Anyway, thats the problem - does anyone have a solution for it - is it a theme issue? (I like this theme, I'm modifying it quite a bit, but the basic layout is exactly what I am looking for)... or should I be looking for an answer somewhere else?

Cheers in Advance

Steve

--- There are no personal problems that can not be overcome with the liberal application of high explosives ---

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Re: Custom page.tpl.php (general Drupal) question

For content type accommodation_listing, you actually want to create a node-accommodation_listing.tpl.php template file, which will be called to display that node type wherever it appears, on any page.

A page != a node; in particular a page can display more than one node, or nodes of different types, so there's really no way to override a page template based on node type. Page templates are named after the URL, not after the content type. For example, page-admin-store-settings.tpl.php will be used if you visit the URL admin/store/settings on your site.

If you want to fake a different page template for each content type, you can always make a page-node.tpl.php and inside that file test if ($node->type == 'accommodation_listing') and execute conditional statements based on the result. Then whenever anyone visits node/#, where node/# is a node of type accommodation_listing, your page-node.tpl.php can display things differently.

(If your theme doesn't have a template.php, and you need to write a theme function override or something like that, just create a template.php in your theme directory and put your overrides in that new template.php. But you don't need to do that for this purpose.)

<tr>.
kiwi_steve's picture
Offline
Joined: 01/14/2008
Juice: 131
Re: Re: Custom page.tpl.php (general Drupal) question

And thats why I bring my problems here... because now I have no problems Smiling Thanks TR - node-accommodation_listing.tpl.php solved the problem... now I just need to rewrite it so that it displays the way I want it to Smiling PHP crash course, here we come...

The other ideas for doing it are interesting too... I might have a play with the php test code inside the page.tpl.php as well

Thanks heaps

Steve

--- There are no personal problems that can not be overcome with the liberal application of high explosives ---