0

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.

Jan Galinski
  • 11,768
  • 8
  • 54
  • 77

2 Answers2

0

okay, I came along with a hack: I include 'sidebar' in the folder name of the module and filter on module.folder name. I am convinced there is a better solution, though!

<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>
Jan Galinski
  • 11,768
  • 8
  • 54
  • 77
0

What you can do (I think) is set a value in the fromtmatter of the module

sidebar: true

Then you can filter on that value in your collection like

{% for module in page.collection() %}
   {% if page.header.sidebar %}
      {{ module.content }}
   {% endif %}
{% endfor %}
user26432
  • 1
  • 2
  • After reading this: https://learn.getgrav.org/content/collections#multiple-collections I think you can create a collection for the main content and a seperate collection for the sidebar content this way – user26432 Nov 09 '17 at 14:41