【问题标题】:grav modular page - separate content and sidebargrav 模块化页面 - 单独的内容和侧边栏
【发布时间】:2017-10-23 00:30:11
【问题描述】:

我想在grav中创建一个页面,其中有一个内容区域和一个侧边栏区域。

我想在 modules.md 根模板上使用,我在其中引用一个循环并显示内容和侧边栏模块的模板。

我的问题是:如何区分内容和侧边栏?

我的模板如下所示:

 {% block body %}
   {% block content %}
   <section id="info">
     <div class="container">
      <div class="row">
        <div class="col-sm-12">
          <div class="row">
            <div class="col-sm-8">
              <div id="content" class="site-content bg">
                <h2 class="heading">{{ page.title }}</h2>
                {{ page.content }}
                {% for module in page.collection() %}
                  {{ module.content }}
                {% endfor %}
              </div>
            </div>
            <div id="sidebar" class="col-sm-4 sidebar-inner">
              {% for module in page.collection() %}
                {{ module.content }}
              {% endfor %}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  </section>
 {% endblock %}
 {% endblock %}

我试图实现的是在两个 page.collections 上都使用过滤器,这样在一种情况下只使用“内容”(我在这里猜测 taxonomy.tag),而在另一种情况下只使用侧边栏。 我可以接受命名约定(侧边栏模块有一个固定的前缀),但我想不通。

【问题讨论】:

    标签: grav


    【解决方案1】:

    好的,我带来了一个技巧:我在模块的文件夹名称中包含“侧边栏”并过滤 module.folder 名称。不过,我相信有更好的解决方案!

    <section id="info">
      <div class="container">
        <div class="row">
          <div class="col-sm-12">
            <div class="row">
              <div class="col-sm-8">
                {% if page.content %}
                  <div id="content" class="site-content bg">
                    <h2 class="heading">{{ page.title }}</h2>
                    {{ page.content }}
                  </div>
                {% endif %}
    
                {% for module in page.collection() %}
                  {% if 'sidebar' not in module.folder %}
                    {{ module.content }}
                  {% endif %}
                {% endfor %}
              </div>
              <div id="sidebar" class="col-sm-4 sidebar-inner">
                {% for module in page.collection() %}
                  {% if 'sidebar' in module.folder %}
                    {{ module.content }}
                  {% endif %}
                {% endfor %}
              </div>
            </div>
          </div>
        </div>
      </div>
    

    【讨论】:

      【解决方案2】:

      你可以做的(我认为)是在模块的 fromtmatter 中设置一个值

      sidebar: true
      

      然后你可以过滤你的集合中的那个值,比如

      {% for module in page.collection() %}
         {% if page.header.sidebar %}
            {{ module.content }}
         {% endif %}
      {% endfor %}
      

      【讨论】:

      猜你喜欢
      • 2018-05-23
      • 2012-12-29
      • 2021-05-29
      • 1970-01-01
      • 2012-01-18
      • 1970-01-01
      • 2013-02-15
      • 2021-10-07
      • 1970-01-01
      相关资源
      最近更新 更多