Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Thank you, but this can't be a View. I think I need to preprocess the field_image variable, but not quite certain how to accomplish that. Commented Jun 27, 2017 at 2:26
  • 1
    "Can't be a view" why can't it be a view? You could knock this out in 2 minutes with a View and a view mode. The View would render the node showing only the image field. You aren't going to be able to inject node fields into various regions by code easily, especially if you are new to Drupal 8. Views is the easiest/best/fastest way to getting that output. Since the View renders a view mode, it has the same twig suggestions (turn on twig debugger), and will trigger the same preprocess hooks if you need them. Commented Jun 27, 2017 at 2:28
  • It can't be a View because I've been writing Views for over 10 years and I wanted to programmatically render the field. It can't be that hard. We're developers and we're smart people who know in the long run, writing this type of code takes less than two minutes and remains much easier to maintain over time. Still working on this... Commented Jun 27, 2017 at 3:58
  • 1
    ... probably takes more than 2 minutes and the code from your answer is not ready for production, there shouldn't be code that breaks the site when you change configuration. The View @Kevin suggested is only a tool to display view modes in a block. Key point is to have these view modes, which you can customize in preprocess and templates. If you don't want a View, then still use view modes to render whole entities. No php necessary, you can use Twig Tweak to render the current node {{ drupal_entity('node', null, 'custom_view_mode') }}. Then the php is maintained by the module. Commented Jun 27, 2017 at 7:18