1

I'm customizing a node type and need to add a webform using the webform module. How do I add the webform in a custom location without having a machine name for the webform?

In the code below for example, I want to populate body content followed by the webform:

<div id="content">    
    <?php print render($content['body']); ?>
    <?php print render($content['WEBFORM?!?']); ?>
</div>

And, yes, I know about displays and how you can change the location of a webform there - my node is too customized.

1
  • If you are using same webform, you can set default setting at content type. Feb 26, 2016 at 2:39

1 Answer 1

0

You were almost there. Use the following code.

<?php print render($content['webform']); ?>

Bear in mind that if you are rendering the webform before the line containing print render($content);, you would need to hide the output of $content['webform'] first, and then render it manually. In this case the code would be similar to the following one.

<?php
// This would go at the beginning of the .tpl.php file, for better readability.
// Hide the webform from rendering, because we will do it manually.
hide($content['webform']);
?>
<div class="content"><?php print render($content); ?></div>
<div class="webform"><?php print render($content['webform']); ?></div>

Generally speaking, I think it is a good practice to always hide elements you want to render separately, just in case at some point you move them before the render($content) line.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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