Adding markup to fields in block plugins I'm attempting to create a block plugin that renders nodes retrieved from a query. I'm able to successfully get the node id's and field values from the query but I'd like to wrap each item in divs and classes but I'm not sure where to start.

public function build() {
    $query = \Drupal::entityQuery('node')
        -&gt;condition('type', 'blog_post')
        -&gt;sort('created', 'DESC')
        -&gt;range(0,3);

    $nids = $query-&gt;execute();
    $build = [];

    foreach ($nids as $nid) {
        $node = Node::load($nid);
        $build[] = $node-&gt;field_image-&gt;view();
    }

    return $build;
}


This is able to render a list of images. But I'd like to be able to have control so I can output something like

&lt;div class="column"&gt;
    &lt;div class="image"&gt;
        &lt;img src="img1.jpg"&gt;
    &lt;/div&gt;
    &lt;div class="bodytext"&gt;
        &lt;p&gt;Body Text&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;div class="column"&gt;
    &lt;div class="image"&gt;
        &lt;img src="img2.jpg"&gt;
    &lt;/div&gt;
    &lt;div class="bodytext"&gt;
        &lt;p&gt;Body Text 2&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;div class="column"&gt;
    &lt;div class="image"&gt;
        &lt;img src="img3.jpg"&gt;
    &lt;/div&gt;
    &lt;div class="bodytext"&gt;
        &lt;p&gt;Body Text 3&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;


Instead of what Drupal wants to output automatically from the view() function.
You can configure a custom view mode with the two fields image and body and then use a twig file:

node--blog-post--my-view-mode.html.twig


And build the node:

$build = \Drupal::entityTypeManager()-&gt;getViewBuilder('node')-&gt;view($node, 'my_view_mode');


Alternatively your task could be easily solved in Views, but maybe this is only an simplified example and you need to do more things in code.