Grav CMS中的唯一页面标识符



我正在使用Grav CMS创建一个模块化网页;然而,我很难根据内容的生成方式自定义布局。

我已经按照文件找到了Grav主网站,我的网站模型。

我的文件夹结构基本上是:

pages
    01.home
         _section1
         _section2

在每个分区文件夹中,我都有自己的.md文件。每个部分都被视为"主页"的一个子页面。

我已经创建了模板文件modular.html.twig,其中有以下代码:

{% extends 'partials/base.html.twig' %}
{% block content %}
{% for child in page.children() %}
    {{ child.content() }}
{% endfor %}
{% endblock %}

这段代码遍历子页面,将内容加载到主页上。在我的模板中,我只是使用{{ content }} 打印内容的结果

我最终得到的是一个具有垂直堆叠内容和重复html的页面,像这样的

我想做的是唯一地定义每个子页面(部分),这样我就可以在html中以不同的方式操作内容。

我曾想过为每个部分创建单独的模板文件,但我的大部分内容都是嵌套的。

例如,我有一个类似于的东西

<div class="row">
   <div class="section-1">
      <h1>{{ content }}</h1>  <!--Needs to be unique-->
   </div>
   <div class="section-2">
      <h1>{{ content }}</h1>  <!--Needs to be unique-->
   </div>
</div>

有可能用这个框架完成我想要做的事情吗?如果是,我该怎么办?

感谢

我认为有很多方法可以做到这一点。对我来说,我使用页面的标题来设置每个部分的CSS类。

我的分区的md文件可能看起来像这样(例如mysection.md)

---
title: Section 1
section_class: section-1
---
This is the content of section 1.

这是我的modular.html.twig:

{% extends 'partials/base.html.twig' %}
{% block content %}
<div class="row">
    {% for child in page.children() %}
    <div class="{{ child.header.section_class }}">
        {{ child.content() }}
    </div>
    {% endfor %}
</div>
{% endblock %}

在我的章节.html.wig中,我打印了该章节的内容

<h1>{{ page.content }}</h1>

我希望这能有所帮助。

最新更新