I am trying to use modular pages as a means to chunk and reuse content over multiple pages.
For example, in one case I’d like to hide a module page section from being displayed in it’s parent but be displayed on another page - is this possible? In another situation I’d like the same module page section to be displayed in it’s parent page and as well in another page - is that possible as well?
I think rather than modular data which is quite specific to being included on a single page, you should simply create a folder pages/modules/ and put your modular/chunk/widget content in there.
Starting to explore this approach, and before I too far I was wondering if the same basic idea would be possible without being theme independent?
For example, would this technique still be effective if I included the needed Twig code within the required pages? I am trying not to tie this solution to a specific theme, if possible.
Well i’m not sure how you could make it completely theme independent. Your talking about rending bits of content in bits of the theme. There is no module/widget position concept in Grav itself, all that is handled by the theme.
Interestingly enough Gantry5 will provide a lot of this infrastructure for Grav allowing you to control layouts and put blocks of content and put Gantry5 Particles into various locations. This is something that is handled by the theme framework layer that sits between Grav and the Theme.
Thanks for the clarifications Andy, I always appreciate all the help you very patiently supply here on the forum!
If I use Grav to create my project, I would want to share the results of my work with other educators so they could use it for their own courses. This is why I was wondering about creating a solution which was not theme-dependent.
Hypothetically speaking, if I proceeded and customized a version of your Bootstrap theme, would it be ok to re-distribute with the proper credit/license?
Yes, that would be fine. Also I think it would be a great idea to release a Skeleton type package for other educators that includes the theme you develop + sample content and configuration. You could always use the theme inheritance of Grav to provide theme customizations without having to completely copy the entire theme and lose updates etc.
I’d love to contribute a Skeleton type package if I can get things going as I hope!
Speaking of which, I’ve been able to get some of what you have described so far but I keep getting an error on a page I am including some Twig on to insert some related modular content.
The page content is:
title: Resources
process:
twig: true
{% include ‘resource-render.html.twig’ with {‘page’: page.find(’/resources/topic1)} %}
But I keep getting this error: Unexpected character “’” in “@Page:/Users/paulhibbitts/Dropbox/MAMP/htdocs/grav/user/pages/02.modu le-1/_resources” at line 2
If I swap out twig: true for markdown: true everything works fine.
Any thoughts? I’ve been clearing the cache as try out things.
Well, that was a bit embarrassing Thanks for pointing that out!
I am trying to get content from /resources/topic1 to display elsewhere, but while I do not get an error anymore (thank you!) I get what looks like an empty result.
The page header is now
title: Resources
process:
twig: true
Page content
{% include 'resource-render.html.twig' with {'page': page.find('/resources/topic1')} %}
For resource-render.html.twig I’ve got:
{{ page.content }}
And in /resources/topic1 I’ve got page header
title: Topic1
Page body:
Resource Topic1
The actual path is “/03.resources/ _ topic2” but if I understand correctly I do not need to include #'s or _'s
Thanks for having a look Andy, I appreciate that. This ability of reusable content is a great feature of Grav, but one that I struggled with to get a working example going.
If it helps you to have access to my test site, I can put it up for you.
I have a plugin i put test templates, but would work the same if you dropped the resource-render.html.twig in the templates/ folder of the theme your using.
I created a default.md page with the same header/content you listed above.
My resources page i put in a folder user/pages/resources/topic1/default.md
Thanks for testing it out, I must have something awry somewhere. Would it be possible for you to share this working example somehow? I really don’t know why I am getting null on my end, thanks.
Thanks very much Andy, I couldn’t get it to work as described but once I dropped the two folders to the page/ folder it worked! I was also able to create a topic2 folder, change the search string, and get the expected results
However, once I tried to do the same technique where the resource topics folders were module components (underline prefix) it once again would result in null results.
Can you duplicate this issue on your end re: using modular folders? i am assuming his same technique would work for either child or module folder content.
Well like I said modular pages in grav won’t work like this. They are considered parts of a page, and won’t be found with page.find(). So that behavior is expected.