【问题标题】:How to render or print node preprocess within the region template如何在区域模板中渲染或打印节点预处理
【发布时间】:2018-10-29 08:16:10
【问题描述】:

我正在执行实体引用以从特定内容下获取节点。我正在寻找如何将我刚刚创建的实体引用函数渲染到我的region.html.twig 模板。下面是我目前正在处理的代码的 sn-p

// Page region level pre-processing
function iom_preprocess_region(&$variables) {


    if ($node = \Drupal::routeMatch()->getParameter('node')) {
        $variables['content_type'] = $node->bundle();
    }


    $elements = $variables['elements'];

    if (array_key_exists('#entity', $elements)) {
        $region = $elements['#region'];
        $entity = $elements['#entity'];
        $bundle = _overrideBundle($entity->bundle());

        preprocess($region, 'region', $entity, $variables);
        preprocess($region."_{$bundle}", 'region', $entity, $variables);
    }
}  

function _preprocess_country_regional_offices_node($entity, &$variables) {

    $entityStorage = \Drupal::service('entity_type.manager')->getStorage('node');
    $regionalOffices = \Drupal::service('entity.query')
        ->get('node')
        ->condition('status', 1, '=')
        ->condition('type', 'regional_office')
        ->condition('field_primary_offices', '1')
        ->sort('created', 'DESC')
        ->execute();

    $regionalOfficeEntities = $entityStorage->loadMultiple($regionalOffices);
    $variables['regional_office'] = $regionalOfficeEntities;


}

【问题讨论】:

    标签: drupal theming


    【解决方案1】:

    我可能会使用暴露的块来执行此操作,但如果您出于特定原因需要在代码中执行此操作..

    $output = render(
      \Drupal::entityTypeManager()
      ->getViewBuilder('node')
      ->view($node, 'teaser')
    );
    

    【讨论】:

      猜你喜欢
      • 2014-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 2021-04-27
      • 2010-11-29
      • 2014-01-17
      • 2015-12-06
      相关资源
      最近更新 更多