0

I'm building a site in Drupal 8 using a content type for products, and I want to show for each product, some "Related Products" that are set in an entity reference field called field_related_products.

Each related product wants to show the title and link (as the field works by standard), but also include the product image and price (defined in fields against each piece of content).

Is there a way to alter the output of the field to do this?

I've seen also that views might be a route to take, but can't seem to get contextual filters to work - the closest I've come is displaying all content that is included as a "related product" throughout the site, which feels a large portion of the way there, but whatever combination I try with contextual filters/default values, it just seems to remove all my results.

Thanks for any advice.

0

You can achieve this by setting a view mode (recommended: Teaser) in the node display for the entity reference field at /admin/structure/types/manage/[CONTENT_TYPE]/display, and then adding the price and picture fields to the Teaser display of the referenced entity.

If the referenced entity is also a node then it would have a similar path of /admin/structure/types/manage/[OTHER_CONTENT_TYPE]/display/teaser. The path would be different if it is not a node, but should be easily found for most custom entities through the UI under the commonly named entity page 'Manage Displays'. Once there view modes can be selected at the top of the page for editing them.

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.