1

维基媒体解释了如何创建基于多个模板的表格,其中每一行都由一个模板组成。

无论如何都要对列做同样的事情吗?这听起来很容易,但我无法让它工作。相反,我的页面显示了多个表格而不是多个列。

这是一些代码:
行页面

{|class="wikitable sortable" style="font-size:85%"
|+ table name
! Title 1
! Title 2
! Title 3
|-
{{R1}}
{{R2}}
{{R3}}
|}

行模板:

| Row 1, Column 1
| Row 1, Column 2
| Row 1, Column 3
|-

栏目页面

{{C1}}{{C2}}{{C3}}

列模板: 不知道这应该如何工作。

4

3 回答 3

3

我知道的唯一方法,除了创建一个带有浮动<div>s 的虚拟表之外,是使用Labeled Section Transclusion (或者如果你有Extension:DynamicPageList,它的等效{{#dpl}}函数)。您使用标签或标题分别标记“列模板”的每个单元格,然后创建一个框架表,通过从列模板中嵌入来填充每一行。结构看起来像这样:<section/>

{|class="wikitable sortable" style="font-size:85%"
|+ table name
! Title 1
! Title 2
! Title 3

|- valign="top
| {{#lst:col1|row1}}
| {{#lst:col2|row1}}
| {{#lst:col3|row1}}

|- valign="top
| {{#lst:col1|row2}}
| {{#lst:col2|row2}}
| {{#lst:col3|row2}}

|- valign="top
| {{#lst:col1|row3}}
| {{#lst:col2|row3}}
| {{#lst:col3|row3}}
...
|}

这种解决方案缺乏像丢弃行那样丢弃列的简单性,但遗憾的是,HTML 并不是为创建真正的基于列的表而设计的。但是,使用这种布局,至少每列中的所有信息都存储在同一页面上,您可以更轻松地对其进行编辑({{col1}}{{col2}}等),如果您正在记录文本信息,那么您还可以将每列读取为可能很方便的不同页面。

如果您打算经常这样做,您可以通过创建一个填充每一行的模板来进一步简化此操作,因此您只需要指定行号,如下所示:(假设您的列始终作为文章的子页面放置他们会出现)

template:col-based table row
{{!}}- valign="top"
{{!}} {{#lst: {{PAGENAME}}/col1 | row{{{1|}}} }}
{{!}} {{#lst: {{PAGENAME}}/col2 | row{{{1|}}} }}
{{!}} {{#lst: {{PAGENAME}}/col3 | row{{{1|}}} }}

然后在标题下你只需要列出:

{{col-based table row|1}}
{{col-based table row|2}}
{{col-based table row|3}}
...

Now, if you want to automatically-generate these rows until you exhaust the template (or in other words, have the table determine how many rows to create without you manually setting them up), that I don't think I can help you with. Perhaps you can do something clever with the DPL extension's table generation function, or install an extension that will allow you to create loops, but I think you'll probably be stuck creating each row manually as described above.

As a final note, because this is content and not formatting I'd advise that you put the column pages in the mainspace rather than the template namespace. In fact, this is the sort of thing that subpages are great for.

于 2013-02-20T15:24:14.563 回答
1

我认为这是不可能的。我想了一会儿,我不知道该怎么做。

也许是某种嵌套模板重新排列了列和行的顺序。似乎非常困难,我不确定理论上是否可行。

于 2010-07-06T15:44:14.513 回答
-1

您可以使用 DIV 获取由模板填充的列,但您必须手动重新创建每个 div 中的每个单元格并重新调整其大小

于 2012-04-17T19:38:34.007 回答