Hello
I recently discovered Grav and I am very happy that I finally found a clean and intuitive flat-file CMS. Thanks to the development team for creating this project!
In the roadmap of Grav 2 I can see that there is a plan of introducing Content Blocks and Widgets, but until we have them, I would like to know what is currently the best practice to reuse parts of content on different pages.
For example, I have a sidebar in which I would like to create some boxes which list links to external websites. In order to separate content and presentation, I created a page (pages/side_menus/default.md) which lists all the links in the YAML FrontMatter section.
menus:
- title: Social Networks
active: true
links:
- title: Facebook
url: #
- title: Twitter
url: #
- title: Youtube
url: #
- title: Related Websites
active: true
links:
- title: website1
url: #
- title: website2
url: #
- title: website3
url: #
---
Then I created a twig tamplate called "sidebar.html.twig" in the 'partials' folder, with the following code:
{% set page = pages.find('/side_menus') %}
<section>
{% for menu in page.header.menus %}
{% if menu.active %}
<h1>{{ menu.title }}</h1>
<ul>
{% for link in menu.links %}
<li><a href="{{ link.url }}">{{ link.title }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
</section>
I could have written the links with markdowns in the content area of the .md file, but I find it more structured in a YAML hierarchy and easier to manipulate from the template file. It also allows me to activate/deactivate a menu easily.
This works, but I have several concerns:
- I first wondered where I should put the links. I did not want to write them directly in the template files which in my opinion should not contain any content. Then I thought about creating a plugin, but it seems overkill for a simple list of links.. I finally decided to put them in the 'pages' folder, although technically they are rather a block to include in pages than a page in itself. Is there a better place to put them?
- From the admin interface, it is strange to go to "pages" in order to edit these links. Additionally it is not possible to see on which pages those side menu will appear.
- I find it strange to create a .md file without content (using only YAML inside the header). Isn't it possible to just create a .yaml file?
In my understanding modular pages allow to create different areas within a page. This may look similar to what I want to do but I am more searching about a way to reuse blocks of HTML & content on different pages of the website.
I would be very happy to hear ideas and advice to achieve this in a better way.
Regards,
Maxime
