【问题标题】:Pass extra variable to Drupal Twig将额外变量传递给 Drupal Twig
【发布时间】:2019-04-03 20:53:30
【问题描述】:

我需要将额外的变量传递给 twig,下面的代码加载 weekView twig 文件,我可以在其中访问 $week_id 的节点,但我也需要访问 $image_path

$week_id = $dynamic_week_id; //comes from different node
$image_path = $dynamic_image_path; //comes from different node

 $view_week_key = [
            'content',
            'this_week_wrapper',
            'this_week',
            'value',
        ];

$form_state->setValue($view_week_key, "<p>[mailchimp_campaign|entity_type=node|entity_id=" . $week_id . "|view_mode=weekView]</p>");

  

【问题讨论】:

    标签: twig mailchimp drupal-8 drupal-theming mailchimp-api-v3.0


    【解决方案1】:

    你用的是什么树枝? 如果它是节点的树枝文件,您可以使用以下方法获取图像:

    {{ file_url(node.field_name.entity.fileuri)}} 
    

    【讨论】:

      猜你喜欢
      • 2019-10-08
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      • 2012-09-09
      • 2016-04-10
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多