Hello drupalers,

Sure hope you guys can help me with this one. I'm kind of a beginner in theming, but I've successfully solved the problems I've encountered so far...

I created a custom theme for a specific content type, because I wanted to get rid of the standard theme header regions and place the CCK fields to my likings. So ive created a page-node-mycontenttype.tpl.php and display the fields like: print $node->field_myfield[0]['view']

So my common logic sensed that there would be no need for the print $content; (thought it only prints the entire list of fields for that content type). But now i can't edit the form in any way (doesn't get displayed). And with the $content the fields get displayed twice.

So my question: How do i get my edit content form displayed without having to use $content. Must be overlooking something here. I've searched everywhere for a solution. Can't be that hard right?

Thanks,

Dave

Comments

gforce301’s picture

If I'm not mistaken you are suing the wrong template. page-node-mycontenttype.tpl.php is a template for the entire page. The template you should be using is node-mycontenttype.tpl.php. Move your code to a file named like that and you should be ok. More information here --> Drupal 6 Template Suggestions

makeapage’s picture

If i use node-mycontenttype.tpl.php ill have all the headers and other stuff i don't want for this content type. It's a popup with an audio player and some custom fields in it..

gforce301’s picture

Reading back through your OP I'm a little confused. Is it that the node add/edit form is no longer displayed when you implement your custom node page without the $content variable being displayed? If this is the case then you will need to add logic to only display your fields when the node is being viewed and not on an add/edit page.

makeapage’s picture

But we are on to something here... but ive had it for today, thanks for your input

gforce301’s picture

You need 2 templates. Read the page I linked previously. In D6 the order in which template suggestions are processed is the problem. You define a page template override for your node type but this also overrides the edit page. So just make another template for the edit page that is the same as the original and your done. You need both these:

page-node-mycontenttype.tpl.php
page-node-mycontenttype-edit.tpl.php

Carolyn’s picture

In your template.php file, you probably have code like:

<?php
  if (isset($vars['node']) && $vars['node']->type != "") {
    $vars['template_files'][] = "page-node-" . $vars['node']->type;
  }
?>

You can add && arg(2) != 'edit' to the if statement, like so:

<?php
  if (isset($vars['node']) && $vars['node']->type != "" && arg(2) != 'edit') {
    $vars['template_files'][] = "page-node-" . $vars['node']->type;
  }
?>
makeapage’s picture

Awesome! i'll try it out. Will let you guys know if it all works out. Thanks allot anyways!

makeapage’s picture

Have been trying it out today... Carolyn's solution seems to be for drupal 5? Or am I mistaken?
Anyways I'm using this in my template.php:

function phptemplate_preprocess_page(&$variables) {

  if ($variables['node']->type == "music") {

    $variables['template_files'][] = 'music';

  }
}

Seems to work well, but its still overriding the Edit page. Adding page-node-stations-edit.tpl.php isn't working either. Is there a way to point the Edit/Add argument to the default page.tpl.php? Btw I'm using drupal 6 and the acquia_slate theme.

Carolyn’s picture

The code above works for me in d6. Have you tried adding && arg(2) != 'edit' to your code? for example:

function phptemplate_preprocess_page(&$variables) {

  if ($variables['node']->type == "music" && arg(2) != 'edit') {

    $variables['template_files'][] = 'music';

  }
}

This docs page may be helpful: Setting up variables for use in a template (preprocess and process functions)

makeapage’s picture

Worked like a charm!...

Thanks for the help!

wolf_22’s picture

Carolyn, I was struggling with the EXACT same situation the OP was going through and your solution not only fixed my problem, but it helped me sleep soundly at night!

;.)

You rock sista! Thanks again for the fix!

makeapage’s picture

Okay so i've upadated to D7. Like i've been expecting: the code ain't working... Drupal 7 is pretty fun so far. It's just a puzzle to get it work in the same way.

makeapage’s picture

Found the solution! Quite odd that page__node__nodetype has to be displayed with underscores instead of hyphens, as the template file is written as page--node--nodetype.tpl.php.

function themename_preprocess_page(&$variables) {

  if ($variables['node']->type == "nodetype" && arg(2) != 'edit' && arg(2) != 'delete') {
	
	$variables['theme_hook_suggestion'] = 'page__node__nodetype';
   }
}

Now it works on D7. Hope this helps anyone out there.
Cheers!

sheldon rampton’s picture

Thanks makeapage for the Drupal 7 update. It worked for me.

----------------
Customer Support Engineer, Granicus
https://granicus.com

thalemn’s picture

Carolyn,

The information you shared was very helpful for me, too. I created a content type and it was associated with a page template - and I couldn't edit the content type. So I followed your instructions and it worked perfectly. I also wanted the user to be able to delete the content via the edit screen, so I added && arg(2) != 'delete' and it worked, too. I hope that was the correct method (I am not a php coder, but understand the basics). Wanted to post this information in case anyone else wanted to add the delete option.

Tom Hale
New Day Web Design
www.newdaywebdesign.com