we’re trying to figure out what’s the best way to insert one modular in specific a specific block in multiple pages. We thought it would be nice to use the page-inject plugin but we also wanted to put the block in different places (Like section top or bottom). We started using a List where you can put the modular-link and a selectbox where we are able to select the destination of the block. Is there an possibility to access the content of the link in our template with page-inject? Because obviously we only get the normal link (plugin:page-inject).
Or does anyone has another/better solution?
Thanks, Phil!
{% for block_entry in header.blocks %}
{% if block_entry.select == top %}
{{ block_entry.link|markdown }}
{% endif %}
{% endfor %}
header.blocks:
name: blocks
type: list
label: Zugeordnete Blöcke
fields:
.link:
type: text
label: Pfad des blocks
placeholder: /bloecke/_ihrBlock
.select:
type: select
label: Wo soll der Block angezeigt werden
top: blue
options:
top: Block oben
bottom: Block unten
---
There really is no one way of doing things in Grav, and you have come up with a pretty ingenious solution that I never even considered Good job!
Gantry5 framework is on it’s way to Grav and it sounds like it will be an ideal solution for you if you need to create more complex shared layouts. Check it out here: http://gantry.org
Right now it’s available for Joomla and WordPress but we are soon going to be bringing it to Grav and it makes a perfect companion for Grav when you need more flexibility and control over layouts.
I think I found a pretty solid solution for this. Now I’m just searching the page with “find()” and get the modular content rendered in the choosen location.
For rendering
{% block block_top %}
{% for blocks in page.header.blocks %}
{% if blocks.select == 'top' %}
{% set blocks_content = page.find(blocks.url) %}
{% include [blocks_content.template, '.html.twig']|join with {'header': page.find(blocks_content.url)} %}
{% endif %}
{% endfor %}
{% endblock %}
For backend
header.blocks:
name: blocks
type: list
fields:
.url:
type: text
placeholder: /bloecke/_ihrBlock
.select:
type: select
default: top
options:
top: Block oben
bottom: Block unten
---