在块模板枝条Drupal 8中迭代列表/内容(Iterate lists/content in block template twig Drupal 8)

编程入门 行业动态 更新时间:2024-10-14 02:25:10
在块模板枝条Drupal 8中迭代列表/内容(Iterate lists/content in block template twig Drupal 8)

我如何能够取代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.value

Thanks

最满意答案

我用它来“生成”我的照片

节点 - 新闻 - full.html.twig

<div class="col-md-3"> {{ content.field_newsbild }} </div>

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

node--news--full.html.twig

<div class="col-md-3"> {{ content.field_newsbild }} </div>

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.

更多推荐

本文发布于:2023-07-07 21:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1068453.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:枝条   模板   迭代   内容   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!