Modular page content chunks

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?

Thanks very much,
Paul

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.

Then you can include anything on any page with a simple page.find(). There is already an example of this kind of thing in the documentaiton

{% include 'modules/module-render.html.twig' with {'page': page.find('/modules/my-module)} %}

Of course you will have to create a simple module-render.html.twig which outputs the {{ page.content() }}

Thanks very much for the helpful info, I’ll explore that approach and see how things go.

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.

Thank you,
Paul

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?

Thanks,
Paul

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.

Thanks,
Paul

Looks like your missing a ' before the last )

{% include ‘resource-render.html.twig’ with {'page': page.find('/resources/topic1)} %}

should be:

{% include ‘resource-render.html.twig’ with {'page': page.find('/resources/topic1')} %}

BTW, try and post code blocks between the triple back-ticks like in regular markdown, makes it much easier to read and see obvious missing things.

Well, that was a bit embarrassing :slight_smile: 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

Any help is greatly appreciated.

Thanks,
Paul

Well that looks about right. I’m probably going to have to try to debug this scenario to see what’s going on.

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.

Thanks,
Paul

I just tested this and it worked 100% fine.

  1. 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.

  2. I created a default.md page with the same header/content you listed above.

  3. My resources page i put in a folder user/pages/resources/topic1/default.md

Results displays fine, just as expected.

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.

Unzip this, and drop the two folders in your user/ folder and point your browser to /twig-render

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 :slight_smile:

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.

Thanks,
Paul

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.

Oh, I am sorry I must have missed that! However, to be honest I would still expect that behaviour to be supported.

Is there another way to achieve the same results, i.e. re-use content from within a module page section on another page?

Thanks,
Paul

Actually you can do this with modular content too:

{% include 'resource-render.html.twig' with {'page': page.find('/test/modular/_callout')} %}

Just tested it.

http://polydeon.com/monosnap/Resources__Demo2_2015-01-15_16-32-34.png