title: Drupal 8 use suggested template when programmatically rendering node
body: <p>I'm <strong>rendering a node programmatically</strong> from within a <strong>Block</strong> class in a <strong>Drupal 8 module</strong> and I would like to be able to use one of the <strong>suggested template names</strong> I get in the generated DOM to <strong>override</strong> how the node is rendered.</p>
  
  <p>Unfortunately, any suggested name I use to create the template in my templates folder is <strong>ignored</strong> and Drupal renders the <strong>basic bartik node.html.twig template</strong>.</p>
  
  <p>Here are the relevant parts of the code :</p>
  
  <pre><code>&lt;?php
  
  /**
    * @Block
    */
  
  
  /**
    * {@inheritdoc}
    */
  public function build()
  {
      $events = [];
      $eventNodes = $this-&gt;repository-&gt;findBy(['status' =&gt; 1], [ 'field_date' =&gt; 'ASC' ]);
      $viewBuilder = $this-&gt;entityManager-&gt;getViewBuilder('node');
      foreach ($eventNodes as $eventNode) {
          $event = EventMapper::fromNodeToEvent($eventNode, [
              'title' =&gt; 'field_titre',
              'start' =&gt; 'field_date',
              'end'   =&gt; 'field_fin'
          ]);
  
          $build = $viewBuilder-&gt;view($eventNode, 'full');
          $event['html'] = $this-&gt;renderer-&gt;renderRoot($build);
  
          $events[] = $event;
      }
  
      $months = [];
      if (count($events) &gt; 0) {
          $indexer = new EventIndexer($events);
          $months = $indexer
              -&gt;indexByMonths()
              -&gt;getResults()
          ;
      }
  
      return [
          '#theme' =&gt; 'calendar_block',
          '#events' =&gt; $events,
          '#attached' =&gt; [
              'library' =&gt; ['calendar/calendar'],
              'drupalSettings' =&gt; [ 'events' =&gt; $events, 'monthsIndex' =&gt; $months ]
          ]
      ];
  }
  
  /**
  * Custom finder in a repository service. get list of nids and load
  * them.
  */
  
  /**
    * @param array $criteria
    * @param array $orderBy
    * @param int   $limit
    * @param int   $offset
    *
    * @return array&lt;Node&gt;
    */
  public function findBy(array $criteria = [], array $orderBy = [], $limit = null, $offset = 0)
  {
      $query = $this-&gt;queryFactory-&gt;get('node');
      $query-&gt;condition('type', self::TYPE);
      foreach ($criteria as $field =&gt; $value) {
          $query-&gt;condition($field, $value);
      }
  
      if (!empty($orderBy)) {
          foreach ($orderBy as $field =&gt; $direction) {
              $query-&gt;sort($field, $direction);
          }
      }
  
      if (!is_null($limit)) {
          $query-&gt;range($offset, $limit);
      }
  
      $nids = $query-&gt;execute();
      $events = $this-&gt;etm-&gt;getStorage('node')-&gt;loadMultiple($nids);
  
      return $events;
  }
  
  /**
    * Twig fragment where the rendered event is printed.
    *
    */
  
  {% for event in events %}
      &lt;div class="js-calendar-slider-event calendar-slider-event" data-start="{{events[loop.index0].start|date('Y-m-d') }}" data-end="{{events[loop.index0].end|date('Y-m-d') }}"&gt;{{ event.html }}&lt;/div&gt;
  {% endfor %}
  </code></pre>