2

I am attempting to use the Form Block module so that I can place one of my content type forms in a block. I seem to be able to get to the block but I'm not sure how to render it. If I do a print_r($block) I see the block contents but I don't see anything to do with rendering it.

$block = module_invoke('formblock', 'block_view', 'csc_newsletter_subscription');

// Normally I would do something like this if it was just a block_view
$variables['newsletter_subscription_form'] = render($block['content']['#markup']);

And then I would be able to take the $newsletter_subscription_form variable and display it in my tpl file, but this does not seem to work.

What am I missing?

2

You can print a Block which is generated by a module like this.

$block = module_invoke(<module name>, 'block', 'view', <block id>);
print $block['content'];

User created block

$block = module_invoke('block', 'block', 'view', <block id>);

example:

$block = module_invoke('block', 'block', 'view', 20);
print $block['content'];

In Your cas, since the forms are in blocks you can simply manage them via exmple.com/admin/structure/block path :)

| improve this answer | |
  • I think that is basically what I have described in my post if I'm not mistaken. Your syntax for D6 and mine for D7 right? If I do the following: $block = module_invoke('formblock', 'block_view', 'csc_newsletter_subscription'); print_r($block); I get an huge array returned but there is no ['content'] item so trying to do print $block['content']; doesn't return me anything. – Chris Casad May 21 '13 at 0:07
  • Ok I think I got it: print render($block['content']); I was missing the render call. Thanks. – Chris Casad May 21 '13 at 0:18

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.