grav modular page - separate content and sidebar

时间:2017-10-23 00:30:12

标签: grav

I want to create a page in grav, where I have a content area and a sidebar area.

I want to use on modular.md root template in which I refer to a template that loops and displays both content and sidebar modules.

My problem is: how to distinguish between content and sidebar?

my template looks like this:

 {% 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 %}

What I try to achieve is to use filters on both page.collections, so that in one case only "content" (taxonomy.tag was my guess here) and in the other case only sidebar is used. I could live with naming conventions (sidebar modules have a fixed prefix), but I can't figure it out.

2 个答案:

答案 0 :(得分:0)

好吧,我来了一个黑客:我包括&#39;侧边栏&#39;在模块的文件夹名称中,并过滤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>

答案 1 :(得分:0)

你能做什么(我认为)是在模块的fromtmatter中设置一个值

sidebar: true

然后您可以在集合中过滤该值,如

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