How to load and render a webform with Ajax I'm new on Drupal 8, and I want to make a custom module to load any webform of (webform module) on other pages of the website.

The idea is to load the webform when the page load. All webform has configured with ajax submission. 

I don't know how I can do that. I someone can help me. I'm on Drupal 8



I've create a custom module with a custom path in routing.yml:

path: '/webform-data/{webformid}'


In my controller I've created a public function to retrieve the webform by id.

I want for example create a link, like:

&lt;a href="/webform-data/{webformid}"&gt;Click&lt;/a&gt;


When I click on the link, the webform load in a wrapper, but when I submit the webform, I have a redirection to the path of webform and I don't want the redirection. I just want the inline confirm message without reloading the page.

I have this in my controller : 

// Controller
namespace Drupal\ajax_webform\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Ajax\AjaxResponse;
use \Symfony\Component\HttpFoundation\Response;

class AjaxWebformController extends ControllerBase {

    public function getWebform($webformid) {

        $build['webform'] = [
            '#type' =&gt; 'webform',
            '#webform' =&gt; $webformid
        ];

        $renderer = \Drupal::service('renderer');
        $rendered = $renderer-&gt;renderRoot($build);

        $response = new Response();
        $response-&gt;setContent($rendered);
        return $response;
    }

}
You might want to look into the Ajax links API.
Sadly, there is an issue with the Webform module and BigPipe that needs to be fixed.