How Page Modules Work in Angular

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 .component.ts and .component.html file in your Angular 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-angular-starter site, the name of the page module is used to find a corresponding .component.ts file 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/app/module-richtextarea/module-richtextarea.component.ts in the ./src/app/module-richtextarea directory.

Screen_Shot_2021-06-21_at_11.22.57_AM.png

Internally, the agility-module.component.ts file will dynamically import the module and pass all the field values for that module as props.

// module-richtextarea.component.ts

import { Component, OnInit, Input } from '@angular/core'; import { IAgilityModuleComponent } from '../../agility/agility.module.icomponent'; @Component({ selector: 'app-module-richtextarea', template: ` <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" v-html="item.fields.textblob" [innerHTML]="textblob" ></div> </div> </div> `, styles: [], }) export class ModuleRichTextAreaComponent implements IAgilityModuleComponent { @Input() data: any; public textblob: string; constructor() {} ngOnInit(): void { this.textblob = this.data.item.fields.textblob; } }

If there is no .component.ts or .component.html file for your module, then nothing can be rendered for it in your Angular 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.

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.