0

I have taken on a site that has hard coded page urls in it's page.html.twig for loading specific sidebar blocks based on the url for related content. eg:

  {% if 'frozen' in url|render|render %}
              {# shows these blocks and in this order #}
              <aside id="sidebar">
                  {{ block_chooserecipes }}
                  {{ block_healthbenefits }}
              </aside>

Is there a way to create a content type field that will load the sidebar blocks that the editor wishes to include with their main content?

2 Answers 2

1

You can have a checkbox field for sidebar block in your content type. Once user selects a set of block to be visible, check those checkbox values in your page.html.twig. Print only those blocks which are checked by user.

1
  • I like this suggestion as it can be implemented with minimal effort. I assume I could use the following condition: {% if node.field_checkbox.value %}
    – Gentwo72
    May 8, 2020 at 14:55
0

First you can create an entity reference field node ->> blocks. Then, create a custom Block visibility condition, like for example web/core/modules/language/src/Plugin/Condition/Language.php Where you can check if the block belongs to the node you are in at the moment.

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.