0

在“content/static-pages/index.htm”上,我可以看到可以在页面上呈现的已保存字段:

然后在局部我可以使用 {{ data.section_color }} 来呈现一个字段。

现在我想在“meta/groups.yaml”中创建一个转发器字段,如下所示:

carousel2:
  name: Carousel2
  description: Carousel2
  icon: icon-file-image-o
  fields:
    section_carousel2:
       type: repeater
       prompt: Add new subitem
       form:
          fields:
            section_carouselimage2:
              label: Image2
              type: mediafinder
              mode: image
            section_carouseltitle2:
              label: Title2
              type: text
            section_carouselsubtitle2:
              label: Subtitle2
              type: textarea
              size: small

我可以在后端看到该字段,并且可以使用它保存数据。在“content/static-pages/index.htm”现在我有:

[viewBag]
title = "Home"
url = "/"
layout = "static"
is_hidden = 0
navigation_hidden = 0
sections[0][section_carousel2][1][section_carouselimage2] = "/carousel/bg-1.jpg"
sections[0][section_carousel2][1][section_carouseltitle2] = "Carousel2 Title"
sections[0][section_carousel2][1][section_carouselsubtitle2] = "Carousel2 Subitle"
sections[0][section_carousel2][2][section_carouselimage2] = "/carousel/bg-2.jpg"
sections[0][section_carousel2][2][section_carouseltitle2] = "Carousel2 Title2"
sections[0][section_carousel2][2][section_carouselsubtitle2] = "Carousel2 Subtitle2"
sections[0][_group] = "carousel2"
==

问题是我找不到渲染这个字段的方法。如何在转发器组内呈现转发器字段?我如何渲染例如“section_title2”字段?

4

1 回答 1

1

嗯,以免假设您正在添加carousel2

好的,我们在meta/groups.yaml中添加了它的标记,所以基本上我们正在制作carousel2组。

所以现在解决方案,我们如何显示它的信息/数据。

首先,我们需要在 cms blocks/carousel2中创建部分内容,因此 carousel2 将放置在其他部分内容所在的 blocks 文件夹中(简单/反应/等...)。

好的,现在我们需要在其中添加此内容

<section>
  <!-- render inner section -->
    {% for slide in data.section_carousel2 %}
        <!-- this block will repeat / based on added slides( so probably slider markup will be here) -->
        <p>{{ slide.section_carouselimage2 }}</p>
        <p>{{ slide.section_carouseltitle2 }}</p>
        <p>{{ slide.section_carouselsubtitle2 }}</p>        
    {% endfor %}
</section>

好的,现在您可以访问 for 循环中的所有字段。我们使用循环是因为您的组是中继器。

让我们稍微理解一下。


data : = 这个变量被传递给每个部分。它关于您的组的数据,在我们的例子中是它的carousel2

现在数据首先有两件事组名其次是我们保存在页面中的真实数据。

要获取已保存的数据,我们现在可以使用data.section_carousel2,因为我们知道它的中继器类型,因此要获取我们需要添加 for 循环的数据。

现在在 for 循环中,我们使用了幻灯片变量,它将为每次迭代获取转发器中所有字段的所有数据。

所以现在在这个循环中你有你的字段slide.section_carouselimage2正如我们在meta/groups.yaml文件中声明的那样。

如果有任何不清楚或不起作用,请发表评论。

于 2017-12-02T15:21:55.363 回答