0

Basically I am using sample code which shown in below.

public function test(){

$webform = \Drupal::entityTypeManager()->getStorage('webform')->load('contact_us');
$webform = $webform->getSubmissionForm();
$dd= drupal_render($webform);

return array(
'#type'=> 'markup',
'#markup' => $dd.'<div><p>test</p></div>'

);

}

I'm using return type markup then form is not rendering properly.So any help available. Thank you all in advance.

1
  • Btw. You should use \Drupal::service('renderer')->renderRoot() instead of deprecated drupal_render().
    – kenorb
    Aug 5, 2017 at 11:02

1 Answer 1

1

This should work if you return $webform; without rendering. Or use the webform render element, then you don't need to load the form:

return [
  'test1' => ['#markup' => '<div><p>test1</p></div>'],
  'form' => [
    '#type' => 'webform',
    '#webform' => 'webform_id',
  ],
  'test2' => ['#markup' => '<div><p>test2</p></div>'],
];
2
  • Thank you for giving me the solution but i also want return type #markup because I also want to render custom html with webform So if any help available thank you in advance. Jul 17, 2017 at 14:17
  • You can return as many render children as you want, see the edit. But don't render early in a D8 controller.
    – 4uk4
    Jul 17, 2017 at 14:59

Your Answer

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

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