How Page Modules Work in Eleventy

Page Modules in Agility CMS are the functional components that make up a page. Editors use these to compose what type of content is on each page and in what order they appear.

Developers define what page modules are available in the CMS and what fields they have. Each module defined in Agility CMS should correspond to a Nunjuck Template in your Eleventy site.

Generally speaking, if you don't have any modules defined or editors don't add modules to pages, then there won't be anything to output for your pages.

Pages, Page Templates, Content Zones & Modules

Learn how pages are generated and rendered

What is in a Page Module?

A Page Module in Agility CMS has a name, description, and fields.

The Name is a representation of the module's intended functionality, such as Posts Listing or Rich Text Area.

It is recommended that each module gets a description, this helps users understand when and where to use this definition.

Fields represent the content that can be managed by editors within the module. These fields are then used in code (passed as props) to display the content the editor intended.

Learn how to How to Create a Page Module.

An Example

In the agilitycms-eleventy-starter site, the name of the page module is used to find a corresponding Nunjuck template that matches the same name. If a match is found, that component is dynamically imported and rendered.

For example, if a module has a reference name of RichTextArea in the CMS, then while the page is being rendered, it will look for ./src/_includes/agility-pageModules/RichTextArea.njk in the ./src/_includes/agility-pageModules directory.


Internally, the render-modules.njk component will dynamically import the module and pass all the field values for that module as props.

{# set module fields  #}
{% set item = module.item.fields %}
<div class="relative px-8"> <div class="max-w-2xl mx-auto my-12 md:mt-18 lg:mt-20"> <div class="prose max-w-full mx-auto">{{ item.textblob | safe }}</div> </div> </div>

If there is no Nunjuck template for your module, then nothing can be rendered for it on your Eleventy site.

How to Change the Fields

You can alter your fields at any time and the field values passed to your component will update automatically the next time you run another build.

1 out of 1 found this helpful



Please sign in to leave a comment.