What's the purpose of modular pages at all?

I just don’t get it. Why do you ever need this? For example, you build a blog, main page would have recent blog entries, articles, news, isn’t easier just set up main template and define blocks in needed places instead of using modular approach? Why does this exists at all? Partials it’s all we needed.

Hi
I agree that partials are good for sites with a fairly fixed layout like a blog but for a site that might need to change more often modular pages are useful for building up a page. There’s nothing stopping you from using partials (headers and footers) along with modular pages (content).

Also far as I know there’s no good way to edit partials from the admin panel. Changing the order of panels on a page is simply drag and drop re-ordering on the page (in admin panel). So modular pages are easier for end users in this sense.

Well, in partials you could have dynamic content, like latest news, etc. No need to edit this for the end user.

Yes this is true and very flexible. I was thinking more like footer links and such which might need infrequent changes.

I mostly use modular pages when I have portion of content that will be repeated on several page, or on pages that would require too much field on a single page.
If you take a look at the homepage of https://getgrav.org/ you can see how many fields it would require on a single page to manage this, and you would not be able to reorganize the module.

So the main assets of modular page is:

  1. Repeatable content
  2. Possibility to organize module
  3. Ease of content edition

Most of the sites I built use modular pages. Paul already gave the main purposes of modular.

The end-user, who manages the site via Admin plugin, can not edit the partials or any line of code in the theme. Imagine what if he wants to move the Click To Action section or Newsletter section from the bottom of the page to the middle of the page just for 1 single page instead of for the whole site, we can’t do this with partials unless you want him to edit the code of the partials via FTP client or hosting service’s file manager, he is not a coder any way.

Hi Paul, that’s what I still don’t get: how would one re-use modular content (not twig templates, this is clear) in other pages? I made a product site with several pages sharing the same content.

I tried with modular design, but couldn’t make use of content between different pages, so I ended up defining content in a hidden file being included using the content-inject plugin. There are lot of dis-advantages with this approach, but while re-using the template of a modular page is easy, I just couldn’t re-use (single) modular page content between different parent pages without duplicating the files. Should hard links be used for this to maintain a single file for editing? Sorry if this sounds as a stupid question, but I have been asking myself the same question as heihachi88 does - why would you need it? (later changed to: how would I use it?) :slight_smile:

As for end-users: since children_display_order: collection setting in admin plugin didn’t work for modular subpages as I expected it (modular pages were displayed in alphabetic order, IIRC), I finally used the numbering sort option, but that’s only a minor annoyance.

TIA, lbc

Hi lbc,

Reusing modular content is simply done by calling page.content, or if from another page:

{{ page.find('/yourmodularpage/_yourmodule').content }}

Keep in mind that this will display the whole modular template + the text content of the module.
That’s what makes modular page special (and useful).

So, to sum up:

{{ page.find(’/some-regular-page’).content }} : this will only display the text that is in the markdown editor of this regular page, but you won’t get the associated rendered template

{{ page.find(’/yourmodularpage/_yourmodule’).content }} : this will display the whole rendered twig template,

I hope this is more clear for you and helps you see the usefulness of modular template (example: for a “subscribe newsletter form” that would be on every page or things like that )?

3 Likes

Hi Paul, thanks very much for the explanation. Yes, now it’s clear to me how to best use modular pages - I was only looking for a way in frontmatter collection definitions, but didn’t think of page collections inside pages.

Used to separate logic and presentation in Smarty templates, maybe I should not apply its policies also to GRAV/twig, since it is much more versatile than other template engines. :grin:
This makes GRAV’s modular pages indeed a very powerful mechanism for including content from other pages, thanks again for your help!

Previously, with another CMS, I’ve actually used a homebrew version of this, i.e. templates that stitch a page together from its child pages. The fact that Grav has a better implemented system out of the box is a big selling point for me.

For me, modular pages come into play whenever a page is composed of sections that together form the content of the page as opposed to its structure. For instance:

Where the parts marked as “partials” would be present on every page of the site. More importantly, users can change the composition of that page themselves, add more than one “Limited time offer” etc.

Another use case would be a page that consists of a list of a dozen or so repeating sections. Say: The list of co-workers of a small company with images and introductory texts. Besides being, IMO, logically more elegant than anything hard coded in a partial, modulars have the added benefit that if that compony later wants to add a page “Our Favourite Ponies” they can just use the same template.

1 Like