我如何能够取代Drupal 8的twig引擎中的层次依赖关系,以便能够在分配给块的列表/视图中循环。 所以我们有一个模板:block - views-block - [machine-name] -1.html.twig你将需要变量{{content}}
然后递归地将其自身埋没到字段模板中。 它彻底杀了我一个人需要这么多级别来制作内容块。
我想在顶部自定义块模板中迭代列表。
尝试
{% for key, value in _context %} <li>{{ key }}</li> {% endfor %}评估可用于迭代到对象但没有运气的可用内容。 我确实找到了一个很好的覆盖对象结构来达到字段属性,但这是在字段级别内
item.content['#item'].entity.uri.value谢谢
How would I be able to supersede the hierarchical dependencies in Drupal 8's twig engine to be able to loop within the i.e Lists/Views which is assigned to a block. So we would have a template: block--views-block--[machine-name]-1.html.twig You will be required to have the variable {{ content }}
Which then recursively buries itself down to field templates. Its completely killing me that one would need so many levels to produce on block of content.
I would like to iterate within the top custom block template the list.
Attempted
{% for key, value in _context %} <li>{{ key }}</li> {% endfor %}To evaluate what is available to iterate down into the object but with no luck. I did though find a nice overriding object structure to reach the field attributes but that was within the field level
item.content['#item'].entity.uri.valueThanks
最满意答案
我用它来“生成”我的照片
<div class="col-md-3"> {{ content.field_newsbild }} </div>节点 - 新闻 - full.html.twig
twig调试建议一些文件名。 我拿了这个:
现场 - 节点 - 现场newsbild - news.html.twig
在那里我写道:
{% for item in items %} <img alt="" src="{{ file_url(item.content['#item'].entity.uri.value) }}" class="img-responsive" {{ attributes }} > {% endfor %}希望我会帮助一下。
i use this to "generate" a picture from my
<div class="col-md-3"> {{ content.field_newsbild }} </div>node--news--full.html.twig
the twig debug suggests some filenames. i took this:
field--node--field-newsbild--news.html.twig
and in there i wrote:
{% for item in items %} <img alt="" src="{{ file_url(item.content['#item'].entity.uri.value) }}" class="img-responsive" {{ attributes }} > {% endfor %}hope i'll help a bit.
更多推荐
发布评论