This question already has an answer here:

On the homepage of my website, I would like to have a block which displays 3 links to inner pages like so: Page example

Each would have the Title of The page, a teaser image that I would like to select to represent each of these links (Since none of the inner pages have images used on them), a small summary and a link to the page. What's the best course of action for me to take in creating this? Would I create a custom view block to display this? If so, are any special settings needed and is there a way for me to select which picture is used through the views settings (overrides?)?

I feel as if this is quite the simple thing to achieve, yet I seem to be overthinking it as I can't come up with a proper solution which would make sense to me.

marked as duplicate by No Sssweat, mradcliffe, Adrian Cid Almaguer, DRUPWAY, Krishna Mohan Jan 27 '17 at 6:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • It's all CSS, just a matter of adding classes. – No Sssweat Jan 26 '17 at 5:18
  • The above link you supplied is not what I am asking for and doesn't relate to my question. I understand how to style it once I have it rendered. My question was the best way to go about rendering said data before styling it out. Thank you, however, Kevin gave me the answer I was looking for below. – ACanadianCoder Jan 26 '17 at 14:16

Multiple ways of doing this depending on what you feel like doing.

Custom block type

Create a custom block type, add the fields you need, add them to a region and set to the homepage. Theme the twig files that relate to this block type.

Paragraph type

You can set up a paragraph type to build this into the node itself. Create a paragraph type that has title, image, summary, and link - then a reference field on the host node that limits the cardinality to 3 total. Theme up the twig files that relate to this paragraph.

Entity reference field on the node

You can even simply set a reference field to other nodes and let the editor enter what nodes they want to reference, and set the field formatter to a display mode (for example 'Call to Action' or 'Card'), and theme those twig files. Simply printing {{ content.field_foo_reference }} will render them as their view mode set in the field formatter. Fields like 'summary' can live on the referenced node - perhaps even a body field that is trimmed (look at adding Smart Trim for better trimming options on long formatted text fields).

Personally, I would go with the third method - it is the quickest of the three to do. I think you can even achieve this with core alone - something you can't do with the second method. It also puts all the work into the node form, instead of require editors to fool with the block system overview and create blocks to do this. Of course, you can also add this reference field on a block type and employ the same method - however since the homepage for me is almost always a node, I like to contain it in the same spot.

  • Excellent! Thank you for the thorough answer Kevin! This definitely clears things up for me for the most part. I'm a little unsure on how to do the third method but once I start applying it, perhaps it'll make sense. – ACanadianCoder Jan 26 '17 at 1:15
  • 1
    You can use entity reference fields to reference existing nodes from this. The upshot is you can set the field formatter display on the field to a view mode - and view modes are very easy to theme. On top of that you can also re-use that view mode for View displays later in other applications of the very same comment. The twig override would be something like node--node-type--view-mode-machine-name.html.twig. – Kevin Jan 26 '17 at 1:22
  • 1
    Here is a reference on Entity Reference fields and what they can do... youtube.com/watch?v=RUx0ZlSGwiM --- might want to check out Drupalize.me too. – Kevin Jan 26 '17 at 1:26

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