2

I would like to render the $content['comments'] part of my nodes outside the node.tpl.php file, and have the comments (form and all) rendered in a separate region of my theme.

I've noticed Commentsblock does something along these lines, but requires a view, and doesn't seem too complete.

Could I do some preprocessing to get the entire comments renderable array into the page.tpl.php template if I'm on a certain node type page, rather than rendering the array inside node.tpl.php? (Something along the lines of this comment).

Also, wouldn't simply not rendering the $content['comments'], and then getting the comments via some other method (like a View, how Commentsblock works) cause Drupal to load all the comments twice (worse performance, etc.)?

6

You should be able to just hide() the comments in the node template and then create a block that calls menu_get_object() and then prints them there...

  • Would this still create a bit of overhead, though? (See the last paragraph in my question). – geerlingguy Jan 4 '12 at 19:08
  • 1
    I've decided to go this route, documenting my method here: midwesternmac.com/blogs/jeff-geerling/… – geerlingguy Jan 4 '12 at 20:06
  • I think the render would only happen once since it should all be cached :) – Jimajamma Jan 4 '12 at 20:27
2

I would suggest you use Panels for this.

  1. Activate the Panels module
  2. Enable the node override, "node_view"
  3. Add a variant, go through the wizard. Most important part in the wizard is creating a selection rule with "Node:type" being the node type you want to do this on. Or any other selection rule that matches your critera.
  4. Click the little cog in a suitable region for the node content -> Node -> Node Content.
  5. Click the little cog in a suitable region for the comment form -> Node -> Comment form.

Other resources: Video introduction to Page Manager and Panels

  • I've seen this solution presented elsewhere, but I'm definitely not going to be using Panels on this site; it needs to be lean and mean, as it has almost 100% authenticated traffic. Page Manager/Panels is a lot of overhead, and a lot of complicated mess, imo, unless you truly use it for everything. – geerlingguy Jan 4 '12 at 19:07
  • 1
    Panels is complicated, that is true. But the the "overhead" statement, I've never seen substantiated. Quite the contrary, we use it on essentially every one of our sites, and many of them are high traffic. Add that it also offers nice caching. To each his own though. – Letharion Jan 4 '12 at 19:53
  • Giving an upvote because it's definitely a solution; just not my favorite (b/c of the complexity, mostly). – geerlingguy Jan 4 '12 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.