1

I have created a module which returns a render array via page callback in hook_menu. The render array contains several arrays that render markup and tables (and data from a particualr node: passed in by a wildcard in the submitted URL). At the bottom of the rendered page I would like the comments and the comments form to be displayed. My plan is to get the comments via a database query, put them into an array and add them to the render array. For the comments form I was going to use the following code:

    $comment = new stdClass;
    $comment -> nid = $nid;
    $form = drupal_get_form('comment_form', $comment);
    return $form;

How do I append this to my page callback function so that my table/markup render arrays and comments/comments form appear on the outputted page?

Thanks. Hope this makes sense. I'm open to changing my plan if you think there's a better approach.

2

Solution

To append the comments form, add this to your render array:

$foo = array(
    'comments' => drupal_get_form('comment_form', $comment),
),

Add this, just above your render array:

$comment = new stdClass;
$comment -> nid = $nid;

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.