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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

Reuse modular content in a different layout?

Started by Cath 7 years ago · 0 replies · 617 views
7 years ago

Basically
I want to use the content of _menulist on another page and with a different layout

footer/_menulist uses template/modular/menus.html.twig

and I want
home/_features with template/modular/menus-features.html.twig ( a layout similar to quark features)

If I create a page home/_features and enable twig I can access the content of _menulist in the same layout of the footer

{% if page.find('/footer/_menulist').published == 'true' %}
{{ page.find('/footer/_menulist').content }}
{% endif %}

the Million dollar question,

Can I change the layout to menus-features?
and if yes what is the best practice or is my logic way off?
I don't want to be duplicating content.

Thanks for the insights!!!


Here's where I'm at....

modular footer

/footer modular

In the footer I have a menu list

/footer/_menulist

The _menulist is created with a custom modular page called menus

The menu template is located template/modular/menus.html.twig and contains this

TWIG
{% set menu_title = page.header.menu  %}
{% if page.header.menu %}<h3>{{ menu_title }}</h3>{% endif %}
<ul>
{% for menu_items in page.header.menu_items %}
<li>
{% if menu_items.url %}<a href="{{ menu_items.url }}">{% endif %}
<i class="fa fa-fw {{ menu_items.icon }}"></i>
{% if menu_items.taxonomy and menu_items.tax == 'yes' %}
{{ menu_items.taxonomy }}
{% else %}
{{ menu_items.text }}
{% endif %}
{% if menu_items.url %}</a>{% endif %}
{% if menu_items.description and menu_items.desc == 'yes'%}
{{ menu_items.description }}
{% endif %}
</li>
{% endfor %}
</ul>

with blueprints/modular/menus.yaml

YAML
title: Menus
'@extends': default

form:
  fields:
    tabs:
      fields:
        features:
          type: tab
          title: Menus
          fields:
            header.menu:
              name: menu
              type: text
              label: Menu Name

            header.menu_items:
              name: menu_items
              type: list
              label: Menu Items

              fields:
                .icon:
                  type: iconpicker
                  label: Icon
                .text:
                  type: text
                  label: Text
                .taxonomy:
                  type: text
                  label: Taxonomy
                .tax:
                  type: text
                  label: Use Taxonomy (yes or no)
                  default: no
                .url:
                  type: text
                  label: Link
                  description: Use full https url for exterior links
                .description:
                  type: textarea
                  label: Description of link
                .desc:
                  type: text
                  label: Show the above description (yes or no)
                  default: no
                .aff:
                  type: text
                  label: Is this an affiliate link (yes or no)
                  default: no
                .hide:
                  type: text
                  label: Hide This (yes or no)
                  default: no

Works as I need by placing this in the footer.html

TWIG
{% if page.find('/footer/_filing-paper').published == 'true' %}
<div class="column {{ columns }} twf">
{{ page.find('/footer/_menulist').content }}
</div>
{% endif %}

this is my menus-features.html.twig

{% set menu_title = page.header.menu %}
{% if page.header.menu %}<h3>{{ menu_title }}</h3>{% endif %}
{% set grid_size = theme_var('grid-size') %}
{% set columns = page.header.class == 'small' ? 'col-4 col-md-6 col-sm-6' : 'col-4 col-md-6 col-sm-6' %}
<section class="section modular-features {{ page.header.class}}">
<section class="container {{ grid_size }}">
<div class="frame-box">
{{ content|raw }}
<div class="columns">
{% for menu_items in page.header.menu_items %}
<div class="column {{ columns }}">
{% if menu_items.url %}<a href="{{ menu_items.url }}">{% endif %}
<div class="feature-icon">
i class="fa fa-fw {{ menu_items.icon }}"></i>
</div>
{% endif %}
<h6 class="caps">{{ menu_items.taxonomy }}</h6>
<p>{{ menu_items.text }}</p>
</div>
</div>
{% endfor %}
</div>
</section>
</section>

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 198 2 months ago
Themes & Styling · by Ian, 2 months ago
3 94 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 455 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 48 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 128 3 months ago