Extending the CWA
An extension is a Nuxt module that adds a feature to any CWA site, for example a shop. A site installs it like any other Nuxt module, and the extension tells CWA what it brings with the cwa:extend hook:
- Components, layouts and page templates, named with the extension's prefix. Editors place them like the site's own, and the site can replace any of them with a file of its own.
- Admin pages under
/_cwa, such as an orders list, with an optional role and an entry in the admin menu. - Paths kept out of the page cache, such as a basket or an account area that differs for each visitor.
It can also listen for sign-in and sign-out, to load or forget what belongs to the visitor.
This section is for developers writing an extension. If you're building one site, put your files in app/app/cwa/ as the Nuxt Module section describes: an extension is for a feature you want to reuse across sites.
What an Extension Is Made Of
The front end of an extension is a Nuxt module with a folder laid out like a site's app/cwa/, plus the Vue files of its admin pages:
cwa-shop/
├── module.ts # registers with cwa:extend
├── cwa/
│ ├── components/
│ │ └── ShopProductCard/
│ │ ├── ShopProductCard.vue
│ │ └── admin/ShopProductCard.vue
│ ├── layouts/
│ │ └── ShopCheckout.vue
│ └── pages/
│ └── ShopProduct.vue
└── admin/
├── orders.vue # an admin list page
└── order.vue # its item dialog
The data lives in the API, as for any CWA component. The API side of an extension is a Symfony bundle that adds its component classes and resources, such as an Order. A component class's name has to match its Vue folder, prefix included (ShopProductCard), because CWA doesn't add the prefix for you. See Architecture › Naming Conventions.
Installing an Extension in a Site
A site lists the extension in modules, beside @cwa/nuxt:
// app/nuxt.config.ts
export default defineNuxtConfig({
extends: ['@cwa/nuxt/layer'],
modules: ['@cwa/nuxt', '@acme/cwa-shop'],})
The order of the two doesn't matter: CWA collects every extension once all the modules have set up.
In This Section
| Page | Go here for |
|---|---|
| Registering an Extension | The cwa:extend hook, the prefix, the cwa/ folder, page cache rules and the build errors |
| Admin Pages | Adding pages under /_cwa, and building a list and an item dialog from the admin's own parts |
| Sign-In and Sign-Out Events | The cwa:auth:signed-in and cwa:auth:signed-out hooks |
Next: Registering an Extension.
Page Caching
How the module lets a shared cache store rendered page HTML, tags it for purging, and works out how long each page can be kept.
Registering an Extension
The cwa:extend hook, the extension's prefix and cwa/ folder, how a site replaces an extension's file, page cache rules, and the build errors.