Twig template for custom entity not working I created a custom entity called 'Representative' using the drupal console 'generate:entity:content' command.

The entity works correctly I added a bundle of fields to it, added some content, and can query this entity using the EntityTypeManager query.

My problem is - I can't render this entity in twig. 
When I pass this entity to the render array:

    $build = [
  '#theme' =&gt; 'representatives',
  '#representative_entity' =&gt; $representative
];


I get the following error:

Exception: Object of type 


  Drupal\kelk_representatives\Entity\RepresentativeEntity cannot be
  printed. in Drupal\Core\Template\TwigExtension->escapeFilter() (line
  476 of core/lib/Drupal/Core/Template/TwigExtension.php).


(I was using drupal console to automatically generate the twig files and preprocess functions)..

Can anyone help?
You must render the correct view mode of the entity, like this:

$view_builder = \Drupal::entityTypeManager()-&gt;getViewBuilder('ENTITY_TYPE');
$entity_view = $view_builder-&gt;view($representative);

$build = [
  '#theme' =&gt; 'representatives',
  '#representative_entity' =&gt; $entity_view,
];