1

I created an entity reference field for a content type, to display related contents. My entity reference view display mixed of 4 content types (Image, News, Document, Biography).

I created a view mode called "Promote" and apply this view mode for 4 content types above.

But i have a trouble with "read more" link for each content type in "Promote" mode.

  • Image content type should show "Go to Image entry"

  • News content type should show "Read more"

  • Document content type should show "Go to Document page"

  • Biography content type should show "View detail"

enter image description here

enter image description here

enter image description here

How can i config the read more link text for each content type based on its view mode ? For example: May be in teaser mode the link text should be "View more".

I prefer not to hard code this in the twig template.

Any help would be very appreciate! Thanks

Updated:

I just pick up some related contents from my entity reference field view and manage display as "Rendered entity".

1

You need to add a new field (Read more text) Then you can rewrite you view result using this field . Add that field in both content type . In views you need to add field content link and in rewrite result you can use (Read more text) field.

  • Thanks for answer. You are talking about the entity reference field display as a View but in my case, i have a entity reference field that helps me pick up some contents and display it as "Rendered entity" with "card" view mode. – Quyet Tran Sep 21 '18 at 8:43
  • You can create twig file for every content type view mode. Like you are using 'card' mode for all content type . You can create own twig file for content type. – Pankaj Yogi Sep 21 '18 at 8:57
  • node--content_type--card.html.twig your twig file name should be like this.Create 4 files as your content type and change Read more button text. – Pankaj Yogi Sep 21 '18 at 9:05
  • Yes, but if so i have to hard code this in the template. The client does not want this. – Quyet Tran Sep 21 '18 at 9:06
  • 1
    @QuyetTran, then you need a hook, see drupal.stackexchange.com/questions/194973/… – 4k4 Sep 21 '18 at 9:49
-1

You can use Views Conditional module which outputs fields based on certain conditions (Content type in your case) that you define in that field.

  • I just pick up some related contents from my entity reference field view and manage display as "Rendered entity". So i think "Views conditional" does not help. Thanks – Quyet Tran Sep 21 '18 at 7:37

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