简体   繁体   English

使用 Twig - D8 将行转换为列

[英]Convert rows to columns using Twig - D8

I have a content type "Awards" that has data structured as below:我有一个内容类型“奖项”,其数据结构如下:

在此处输入图像描述

I want to group this data as below:我想将这些数据分组如下:

Want to group them on a "State" basis.想要在“状态”的基础上对它们进行分组。 So when I click on mysite.com/TXawards, it should show data grouped as below:所以当我点击 mysite.com/TXawards 时,它应该显示如下分组的数据:

在此处输入图像描述

Similarly "/FLaward" page should show data grouped as above.同样,“/FLaward”页面应显示如上分组的数据。 I don't have a view created yet but the content type with data is ready.我还没有创建视图,但包含数据的内容类型已准备就绪。 What would be the best way to achieve this?实现这一目标的最佳方法是什么? I was thinking to use a contextual filter but I click the link "/TXawards" which is hardcoded on a page.我正在考虑使用上下文过滤器,但我单击了页面上硬编码的链接“/TXawards”。 Any help on how to group this data?关于如何对这些数据进行分组的任何帮助? Thanks谢谢


UPDATE : I created a"Table" styled view and grouped the rows by Type and State. The view output looks as below.更新:我创建了一个“表格”样式的视图,并按类型和 State 对行进行了分组。视图 output 如下所示。 在此处输入图像描述

Can someone help with twigging this output to 2 column format pls?有人可以帮助将此 output 转换为 2 列格式吗?

so this answer that I have doesn't go about transposing your table using the twig templates.所以我的这个答案不是 go 关于使用 twig 模板转置您的表格。 What this does is just give you the data in the direct format from Views and then you can style and format it however you'd like.这样做只是为您提供来自视图的直接格式的数据,然后您可以根据自己的喜好设置样式和格式。

Since I don't have your fields or project I can't really give you a view export, however I can walk you through a few steps to set it up.由于我没有您的字段或项目,因此我无法真正为您提供视图导出,但我可以引导您完成几个步骤来进行设置。

EDIT: I figured that I might as well toss in the export of the mock-up view I made to make these screenshots. Also, this concept should be applicable for Drupal 7-9, but the export linked may only work for 9.x

Export of Drupal v9.3.12 View that was built as concept for answer.导出 Drupal v9.3.12 作为答案概念构建的视图。

Mark all fields hidden, except one标记隐藏的所有字段,除了一个

Drupal 视图隐藏字段

  • All the fields you want to show, make them hidden.所有你想显示的字段,让它们隐藏。
  • Whatever formatting you use will still be output for the each field (ie link, date format, etc.)无论您使用何种格式,每个字段(即链接、日期格式等)仍然是 output
  • I typically keep all the fields I plan on outputting hidden, and for the last field I add like an ID content field or something.我通常会隐藏我计划输出的所有字段,并为最后一个字段添加 ID 内容字段或其他内容。

Set the one last non-hidden field to re-write with tokens将最后一个非隐藏字段设置为使用标记重写

Drupal 视图使用替换标记重写字段

  • You can style the overall format however you want it to rewrite.您可以设置整体格式的样式,但您希望它重写。
  • Your example is looking for a 2x4 table, so thats what I put in for mine.你的例子正在寻找一个 2x4 的桌子,所以这就是我为我的。
  • All the variables that are wrapped in double brackets are taken from the Replacement Patterns accordion below.双括号中的所有变量都取自下面的替换模式手风琴。
  • Any field you included and set as hidden should be shown and be available as a token for rewrite.您包含并设置为隐藏的任何字段都应显示并可用作重写的标记。
  • For my example I did just basic fields, title, user, date, etc.对于我的示例,我只做了基本字段、标题、用户、日期等。

Set the Format > Format to be Unformatted list instead of Table将格式 > 格式设置为无格式列表而不是表格

  • Now for this, if you really want, can make it any of the formats.现在对于这个,如果你真的想要,可以把它做成任何格式。
  • I think Unformatted list will give you the easiest markup to work with我认为无格式列表会给你最容易使用的标记

Preview the results预览结果

Drupal 视图以未格式化的列表格式预览重写的字段

Lastly, configure the view and everything else as necessary.最后,根据需要配置视图和其他所有内容。 Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM