Drupal 8:联系内容类型关联反馈表单及页面配置咨询
Hey there! Let's work through your two options for integrating the contact form with your custom contact content type in Drupal—both are totally doable, so let's break them down clearly:
Option 1: Embed the contact/feedback Form Directly Below Your contact Content Type's Body
If you want the form to show up automatically on every contact type node right below the main body content, here's how to do it with core tools (no extra modules needed):
- First, make sure the core Contact module is enabled (head to Structure > Modules and check the box next to Contact if it's off).
- Turn your
feedbackcontact form into a block:- Go to Structure > Blocks > Place block, search for "Contact form" and find your
feedbackform's block entry. Click "Place block". - In the block settings, jump to the Visibility tab. Under "Content types", only check your custom
contactcontent type—this ensures the block only loads on those nodes. - For the Region dropdown, pick the region that sits right below your content body (this depends on your theme, but common options are "Content bottom" or "Post content bottom"). Save the block configuration.
- Go to Structure > Blocks > Place block, search for "Contact form" and find your
- If you need more control over exactly where the form renders (like embedding it inside the content flow instead of a fixed region), you can use a custom template:
- Create a template file named
node--contact.html.twigin your theme's templates folder. - Add this Twig code wherever you want the form to appear (typically right after the body field):
{{ drupal_form('Drupal\\contact\\Form\\ContactForm', 'feedback') }} - Clear your Drupal cache, and the form will render exactly where you placed it in the template.
- Create a template file named
Option 2: Add a Managed HTML Block Above the contact/feedback Form Page
If embedding the form directly on the contact node isn't feasible, you can easily add and manage custom HTML content above the standalone contact/feedback form page:
- Create a custom HTML block:
- Go to Structure > Blocks > Add block, select the "Custom HTML" block type.
- Fill in a title (you can choose to hide it on the frontend if needed) and your desired HTML content using the rich text editor. Save the block.
- Place the block on the
contact/feedbackpage:- Go back to Structure > Blocks > Place block, find your new HTML block, and click "Place block".
- In the Visibility tab, select "Pages" and enter
contact/feedbackin the text field—this restricts the block to only show on that exact form page. - Choose a region that appears above the form (like "Content top" or "Page header", depending on your theme) and save the settings.
- To edit the HTML content later, just head back to Structure > Blocks, find your block, and click "Configure"—you can update the content anytime without touching code.
内容的提问来源于stack exchange,提问作者The Old County
相关产品推荐
相关产品推荐

