Created
February 16, 2012 19:04
-
-
Save rpersaud/1847060 to your computer and use it in GitHub Desktop.
Drupal Render Form node.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="content clearfix"<?php print $content_attributes; ?>> | |
<?php | |
// We hide the comments and links now so that we can render them later. | |
hide($content['comments']); | |
hide($content['links']); | |
drupal_render($content); | |
// display only for authenticated users | |
global $user; | |
if ($user->uid) { | |
$form = drupal_get_form('sample_form'); // generates array | |
print drupal_render($form); // prints out html | |
} | |
?> | |
</div> |
By calling the form in the preprocess phase, you can print out the results via print render($my_form);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently, its bad practice to mix business logic with presentation by making a function call to render the custom form in the template file. There are more elegant solutions, based on what you're trying to accomplish, here is the initial thread that sheds more light on the topic - http://drupal.stackexchange.com/questions/22815/best-way-to-render-a-form-on-a-node