I'm using Drupal 8, including paragraphs.

I have a content type with a paragraph field, and this paragraph contains a fieldgroup of two fields that display in horizontal tabs.

When adding content, on save only the content in the active tab should be set to display on the page. In other words, you choose one tab or the other, add content into its designated field and save. The content in that active tab is the content that will display when viewing the page (even if there is content in the other tab).

How can I display the content from only the tab that was active on save?


Add a text field OR boolean field to your content type, let's call it "Active Tab".

Using jQuery you can make it when tab x gets clicked, it auto fills the text field OR auto checkmarks the x boolean box. (You can hide this field with CSS if you want).

Use a template file to control the display/output. So simply in your twig template file perform an conditional statement

{% if content.field_active_tab.0 == 'x' %}
  {{ content.field_something }}
  {{ content.field_something_else }}
{% endif %}

{% if content.field_active_tab.0 == 'y' %}
  {{ content.field_something2 }}
  {{ content.field_something_else2 }}
{% endif %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.