0

enter image description hereenter image description hereenter image description hereenter image description hereI am attempting to add a webform field into an existing content type which has an associated twig template. I can add the webform field to a new content type and/or use the default webform content type and the form displays without an issue. If I add the webform to an existing content type the form does not display. I tried adding the content from webform.html.twig to the existing content types template but it is still not displaying the form. I know I am missing something simple here. I can supply a few screenshots and or the twig files if that would be helpful

thank you for your patience. I have had the debugging turned on for quite some time now the development version of our site. The inspect screen appears to suggests the problem with displaying the webform field is in the page.html.twig which I have attached. Interestingly, I tried adding a few other random fields to the page content type and they do not display either so I am fairly certain now that there is a problem with the twig template.

{#
/**
 * @file
 * Default theme implementation to display a page.
 *
 * @see academyhealth.info.yml
 * @see template_preprocess_page()
 * @see html.html.twig
 *
 * @ingroup themeable
 */
#}

<header class="header">
  <div class="container">
    <a class="header__logo" href="/"><span class="element-invisible">AcademyHealth</span></a>
    <button class="header__menu-button"><i class="icon-hamburger"></i> Menu</button>
    <div class="header__navs">
      <a class="js-navs__close" href="javascript:void(0);"><i class="icon-close"></i> <span class="element-invisible">Close</span></a>
      <nav class="header__main-nav">
        {{ page.main_navigation }}
      </nav>
      <div class="header__util">
        {{ page.utility_navigation }}
        <div class="util__search">
          {{ page.search }}
        </div>
      </div>
    </div>
  </div>
</header>

<section class="page">
  {#
    A block titled content will be set if pages are extending this template, so
    print that instead of just printing page.content. The templates that extend
    this template, call page.content and place it appropriately.
  #}
  {% set _block_content = block('content') %}

  {% if _block_content is not empty %}
    {{ _block_content|raw }}
  {% else %}
    {{ page.content }}
  {% endif %}

</section>

<footer class="footer">
  <div class="container">
    <div class="footer__col1">
      <a class="footer__logo" href="{{ site.url }}"><span class="element-invisible">AcademyHealth</span></a>
    </div>
    <div class="footer__col2">
      <h6 class="footer__title">Connect with Us</h6>
      {{ page.footer_social_media }}
    </div>
    <div class="footer__col3">
      <h6 class="footer__title">Navigate AcademyHealth</h6>
      {{ page.footer_menu }}
    </div>
    <div class="footer__col4">
      <h6 class="footer__title">Extras</h6>
      {{ page.footer_extras }}
    </div>
  </div>
  <div class="footer__credits">
    <div class="container">
      {{ academyhealth_address_line }} | {{ academyhealth_address_line_2 }} | Tel: {{ academyhealth_phone_number }} | Fax: {{ academyhealth_fax_number }}
    </div>
  </div>
</footer>
2
  • Welcome to Drupal Answers. When you ask a question, it usually helps to add the "7" or "8" tag so we know which Drupal version you're asking about. In fact, you can still edit your question and add it. In this case I'm going to guess 8 because you said "twig". Commented Jun 9, 2018 at 19:30
  • In a site setup that I would consider "normal", I don't see how this could be a problem with blocks or the page template. In other words: If this is not a problem with the configuration of your view mode (which, as you have checked, it is not) or the node template (which you say it is not), then I'm running out of plausible options. That could also mean your question is so specific to your site and custom code, that it is beyond the scope of Drupal Answers. Commented Jun 11, 2018 at 10:19

1 Answer 1

2

Conceptually, you shouldn't be thinking about it as including templates in other templates. Other CMS'es are more "template based" so to speak, but Drupal isn't. Building your content types and pages in Drupal means telling Drupal (through configuration or in code) how to construct its render arrays. From there on, Drupal will figure out which templates to use and how to merge the resulting HTML of one template into another template.

So that's the theory... now what's the problem in your case? The most obvious reason I can think of, is that you added the field, but did not yet configure it to be displayed. To do so, make sure Field UI module is enabled and then go the "Manage Display" page of your content type. The URL will look like /admin/structure/types/manage/[type]/display where "[type]" is the machine name of your content type. If you see your field in the "disabled" part of the form, drag it upwards to make it enabled and save the form. (This is an example of the "through configuration" method I mentioned earlier.)

If the above does not solve your problem, please add more details to your original question.

3
  • Thank you and I apologize you are correct I am using Drupal 8.5.4. I had already confirmed that the webform field is listed in the enabled section of the Manage Form Display and under the various views under the custom display settings. If I use the webform included content type the webform displays as expected. If I change the theme to the default seven the page with the webform field will display the webform and other fields correctly. Using our theme the page will display all of the content with the exception of the webform field (which it just seems to ignore) correctly Commented Jun 10, 2018 at 12:18
  • So you tried if it does work in a different theme - excellent! That is a great way to determine if the problem is in your configuration or in your theme. Obviously it's in your theme. Maybe you can add the code of your custom node template to the original question? If you are not sure which template is used, follow these instructions to find out. Commented Jun 10, 2018 at 15:47
  • Based on your earlier comment I also wonder if this couldn't have something to do with the region blocks. I looked at the ones for defined for content and there doesn't seem to be restriction on the webform content type but I may not be looking at the correct information Commented Jun 10, 2018 at 16:17

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.