D
D
Dmax992021-06-30 21:56:05
Drupal
Dmax99, 2021-06-30 21:56:05

How to place a contact form (webform) in the body of the page?

Hello! Please tell me, otherwise I don’t understand (inexperienced)
I created a feedback form, and I want to place it in the body of a page or article. How can I do that?
The text is in CKEditor, maybe there is some shortcode that will work?
Drupal 8
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
andead, 2021-07-01
@andead

// THEMENAME.theme

function THEMENAME_preprocess_node__NODE_ID(array &$vars) {
  $webform_build = [
    '#type' => 'webform',
    '#webform' => 'WEBFORM_ID',
  ];
  $vars['content']['body'][0]['#text'] = str_replace('[webform]', render($webform_build), $vars['content']['body'][0]['#text']);
}

did not check

A
antiden, 2021-07-01
@donda

Webform can be rendered as a block. From here, there are many options for how to withdraw:

  1. Block management, display a block, specify conditions, for example, for the /about page
  2. Put paragraph + paragraph_blocks . In the Paragraph Manager, add a type, for example Block, add the paragraph_blocks field to the created paragraph. For the content type, add a paragraph field and select the created type Block, output as you like. Simple constructor.
  3. Install twig_tweak + output via twig. Use cheat sheet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question