CWA 2 is a prerelease (2.0.0-alpha), heading for a beta. It runs production sites; configuration can still change between releases, always with upgrade notes. View versions and support
Extending the CWA

Extending the CWA

What a CWA extension is, what it can add to a site, and how its files are laid out.

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.

Image placeholder: the admin menu open, with an Extensions heading listing an extension's Orders page, and the orders list beside it.

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

PageGo here for
Registering an ExtensionThe cwa:extend hook, the prefix, the cwa/ folder, page cache rules and the build errors
Admin PagesAdding pages under /_cwa, and building a list and an item dialog from the admin's own parts
Sign-In and Sign-Out EventsThe cwa:auth:signed-in and cwa:auth:signed-out hooks

Next: Registering an Extension.