Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Modular page with collection in one of the modules

Started by Muut Archive 10 years ago · 3 replies · 490 views
10 years ago

I'm trying to make a modular page with a collection as one of the modules.

Something like this:
Home

  • Rotator (module 1)
  • Tagline (module 2)
  • Content (module 3)
  • Capsules (collection of call to actions)

Home has an md called modular.md like this:
content:
items: '@self.modular'
order:
by: default
dir: asc
custom:

  • _mission
  • _content
  • _capsules

Capsules has an md called capsules.md like this:
content:
items: '@self.children'
order:
by: date
dir: asc
limit: 3
pagination: false

Then in templates, I have a modular.html.twig. What do I do for the template for capsules? It should be in the modular folder, right, and have a regular collection?

TWIG
        {% for p in page.collection %}
            <div class="col-md-4">
                <div class="capsule-gates">
                    <a href="{{ p.link }}" class="btn btn-wide icon-left"><h3>{{ p.title}}</h3>     
                </div>
            </div>
        {% endfor %}

It's not pulling the capsules, so I have something not hooked up correctly somewhere, any ideas?

Thanks!

10 years ago

Please include the code in triple backticks, or --- next time, to make sure the forum formats it readable.

Re-posting it here below:

I'm trying to make a modular page with a collection as one of the modules.
Something like this:

TXT
Home
– Rotator (module 1)
– Tagline (module 2)
– Content (module 3)
– Capsules (collection of call to actions)

Home has an md called modular.md like this:

YAML
content:
 items: @self.modular’
 order:
  by: default
  dir: asc
  custom: 
    mission
    content
    _capsules

Capsules has an md called capsules.md like this:

YAML
content:
 items: @self.children’
 order:
  by: date
  dir: asc
  limit: 3
  pagination: false

Then in templates, I have a modular.html.twig. What do I do for the template for capsules? It should be in the modular folder, right, and have a regular collection?

TWIG
{% for p in page.collection %}
 <div class=“col-md-4”>
  <div class=“capsule-gates>
   <a href=“{{ p.link }}class=“btn btn-wide icon-left><h3>{{ p.title}}</h3>
  </div>
 </div>
{% endfor %}

It's not pulling the capsules, so I have something not hooked up correctly somewhere, any ideas?

10 years ago

And the answer it, is should work with a capsules.html.twig under the templates/modular/.

You can also debug inside the capsules.md file directly, by adding

YAML
process:
    twig: true

to the page header, and

TWIG
{{ dump(page.collection|length) }}

inside the page.

I don't know if this is the problem, but the line items: ‘@self.children’ you pasted does not have valid quote symbol. != '

10 years ago

Thanks, I'll try that. I didn't know about the --- either so that's helpful.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1370 9 years ago
Archive · by Muut Archive, 9 years ago
2 943 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1127 9 years ago