Training

Our next U.S. stop:

Mike Anello and Andrew Riley from Mediacurrent are teaming up to offer the first Blue Collar Git workshop on Friday, June 8 as part of DrupalCamp Charlotte (also part of the Southeast LinuxFest). The cost is only $149 for the full day if you register during the month of May ($199 otherwise). 

New Podcast

Posted Wednesday, May 9 at 7:50 am
Brandon Morrison (Brandonian on drupal.org) joins Andrew Riley and Mike Anello on the first post-DrupalCon Denver edition of the podcast to talk about all things Geo in Drupal 7. Brandon is one of the maintainers of the GeoField module and is an active member of the Drupal Geo community.
Download Podcast 82
DrupalEasy_ep82_20120509.mp3
Syndicate content

Newsletter

Stay up-to-date on DrupalEasy workshops and other events. On average, we send about one newsletter per month.

Testimonial

Mike is a great teacher!

Who are we?

DrupalEasy is the collective expertise of Ryan Price and Michael Anello, who joined forces to provide training and consulting services worldwide. Read all about them and what they can do.

What is Drupal?

Drupal is a free, super-powerful content management system for sites that require information posting and collection, including blogs, forums, videos, photos, and databases of information. We think it is the best platform available. Here's why...

Why Drupal?

More and more savvy organizations are going with Drupal for content management, and its no mystery why. It’s free, flexible, and easy to maintain for small or large volume sites. Learn more...

Moving the comment form without hacking core

Average: 4.3 (14 votes)

One of the most frustrating things about Drupal's current architecture is that comments, and the form to post them, are attached to nodes and don't easily allow you to move them around in your TPL files. There really should be an easier way to just place them anywhere you'd like. Most times this doesn't get in your way, until you want to do some fancy layouts where your content is split into multiple columns on the page. After going round and round with this, I finally happened upon a discussion on Drupal.org that solves this for 5.x rather easily with a snippet of PHP:

<pre>
if (function_exists('comment_render') && $node->comment) {
   print comment_render($node, $node->cid);
   $node->comment = NULL;
}
</pre>

Just place this code anywhere in your TPL files where you'd like to move the comments and be happy that you didn't hack core.

Happy Drupaling!

Trackback URL for this post:

http://drupaleasy.com/trackback/14

10 comments

Guest wrote 3 years 12 weeks ago

Are there any modules that

Are there any modules that allow you to make changes to the comment form (number of rows in text area, hiding elements, etc?)

Guest wrote 3 years 16 weeks ago

This is a great hack, but as

This is a great hack, but as soon as i make a mistake on the comment form (empty or wrong captcha), the page is displayed again with the hack not working, the form is outside the node again... if (function_exists('comment_render') && $node->comment) returns true... Do you have an idea ?

David Peterson wrote 3 years 18 weeks ago

You are brilliant!! I have

You are brilliant!! I have been searching for something like this for a long time and couldn't get it going. Thank you.

ryanprice wrote 3 years 22 weeks ago

ajay, You'd still use this

ajay,

You'd still use this snippet.

As the original thread states, you'd put this where you want it in your node-TYPE.tpl.php, and the regions should be available on node templates just as easily as page templates.

Correct me if I'm wrong.

For Drupal 6, check out Joon's comment a few lines down:
http://drupal.org/node/122240#comment-707961

ajayg wrote 3 years 23 weeks ago

It works if you want to

It works if you want to treat comments list and the new comments form as one block. But if you want to insert a region say in between list of comments and new comments form, how would you do that?

Lopsta Ecommerce wrote 3 years 24 weeks ago

themeing stuff is such a

themeing stuff is such a nightmare on drupal. everything else i just love, but getting the html output that you plan to get is a real pita. but i have to say i'm still on D5, ppl told me D6 is much better.
Anyway, thanks for sharing the code.

ericmarden wrote 3 years 32 weeks ago

You can, but I tend to use

You can, but I tend to use mini-panels more, and just place them in custom block regions, instead of using full blown panel pages. Plus, for the end node pages, sometimes you just want to move it for one type of content, and not all the others.

- Eric Marden

- Eric Marden

ryanprice wrote 3 years 32 weeks ago

@venkat-rk While I agree

@venkat-rk

While I agree that you could probably create a single panel that drives EVERY page on your site, sometimes you just need to hand a brother a .tpl.php file, you know?

Davy Van Den Bremt wrote 3 years 32 weeks ago

Great tip! If only I had

5

Great tip! If only I had known this earlier. Needed this on http://www.donna.be and a few other sites.

Thanks!

venkat-rk wrote 3 years 32 weeks ago

Couldn't this be done with

3

Couldn't this be done with panels?

Syndicate content