How to use different displays for the same component

Created on 12 February 2024, 9 months ago
Updated 3 April 2024, 8 months ago

Problem/Motivation

I'm wondering if I should be able to do the following, somehow, and if so, how?
Let's say I have a component fielded as a news article, and that the full component (all fields) would be shown on a detail page. This would be the use case that is evident with this module, where I create a news-detail display and map it to the news component. But what if I want a subset of the fields (teasers) on a news landing page?

How would I map the additional display? If I map it to the same component, the twig file would need to handle both possibilities (teaser and detail). If I create a new component, it wouldn't contain the data from the original, unless I import the original in the twig file. I could do it with a view, but then the view would not make use of a twig file, defeating the purpose of having components.

I'm guessing there is a way to do this, but a clean non-hacky way is eluding me.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Fixed

Version

1.0

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States j. ayen green

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @j. ayen green
  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    I think you would create another display mode and a new component.

    The details component could embed the landing component if it makes sense to structure that way. Otherwise, just create a new component with an extended list of props and slots.

    I used layout builder and ctools entity display to embed another display inside a display mode.

  • e0ipso Can Picafort

    @mortona2k that is a cool technique! I would love to know more about it. Would you be up to providing a short screencast explaining it? Or maybe even some explanatory screenshots? I know I am asking a lot from you lately, feel free to tell me so. I appreciate your involvement!

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    I'm experimenting with some different things, still very new to using this module.

    Here I had a display mode for "Artwork info", and am replicating that inside the "Content Header" display using a field group w/ SDC.

    Alternatively, I could include the artwork info component inside my content header component.

    What I mentioned with layout builder lets you reuse display modes inside a layout. However if you're using layout builder for a display, you can't also render it as a component.

    I got around that by including components in my node display mode templates, which is the technique I was using before using SDC Display.

  • Status changed to Fixed 8 months ago
  • e0ipso Can Picafort

    Thanks for offering a solution @mortona2k!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024