Emfasi-Developer
4/18/2018 - 9:21 AM

Render custom block preprocess

Renderitzar un custom block per poder pasar-ho al template de la vista.

<?php 

function template_preprocess_views_view_unformatted(&$variables){
  
  // CHECK WIEW FOR RENDER ONLY IN THIS (view id - display id)
  $view = $variables['view'];
  $id = $view->storage->id();
  $display_id = $view->current_display;
  if($id === 'view_id' && $display_id = 'display_id') {
    
    // RENDER BLOCK
    $bid = 3; // BLOCK ID
    $block = \Drupal\block_content\Entity\BlockContent::load($bid);
    $render = \Drupal::entityTypeManager()->
      getViewBuilder('block_content')->view($block);
      
    // PASS BLOCK TO TWIG VARIABLE
    $variables['block_name'] = $render;
  }
  

}