Layouts
A CWA layout is the outer shell of your site — the header, footer, navigation, and any component groups that persist across pages. The PHP API has a Layout entity whose uiComponent value maps to your Vue file.
File Convention
app/app/cwa/layouts/primary.vue → registered as CwaLayoutPrimary
The Layout resource's uiComponent holds the full registered name, CwaLayoutPrimary. The admin panel stores that for you. The naming rule for layouts, page templates and components is below.
How uiComponent Names Resolve
The module registers the files in three directories as global components, each with its own prefix. Nuxt builds the name from the prefix and the PascalCased path below the directory:
| Directory | Prefix | Example file | Registered name | What uiComponent stores |
|---|---|---|---|---|
app/app/cwa/layouts/ | CwaLayout | primary.vue | CwaLayoutPrimary | The full name, CwaLayoutPrimary. It is rendered as stored, so Primary doesn't resolve |
app/app/cwa/pages/ | CwaPage | BlogDetail.vue | CwaPageBlogDetail | The full name, CwaPageBlogDetail. The API adds the CwaPage prefix when a page is written with the short name, so the admin, the fixture builder and your own API calls all store the same value |
app/app/cwa/components/ | CwaComponent | Title/Title.vue | CwaComponentTitle | Nothing by default: a component renders by its type (@type). Picking a ui/ variant in the admin stores the variant's full name, such as CwaComponentNavigationLinkUiYouTube for NavigationLink/ui/YouTube.vue, or CwaComponentFormUiExampleForm for a form. The module renders it with or without the CwaComponent prefix |
Three consequences:
- The prefix is added to whatever the file is called.
PrimaryLayout.vueregisters asCwaLayoutPrimaryLayout, notCwaLayoutPrimary, so that is the nameuiComponentmust hold. A short file name such asprimary.vuekeeps the names readable. - Nuxt PascalCases the file name, so
primary.vueandPrimary.vueboth register asCwaLayoutPrimary, andsite-header.vueasCwaLayoutSiteHeader. - Only a component's own folder file is a type.
Title/Title.vueis theTitletype andTitle/ui/*.vueare its variants; any other file in the folder, such as one inTitle/_parts/, is neither.
BlogDetail, and the admin selects the right Page UI for it. prefix-page-ui-components rewrites such rows to the full name. Layouts are stored as sent, with no prefix added.Minimal Layout
<!-- app/app/cwa/layouts/primary.vue -->
<template>
<div>
<header>
<NuxtLink to="/">Home</NuxtLink>
</header>
<main>
<slot />
</main>
<footer>
<p>© 2024 My Site</p>
</footer>
</div>
</template>
<script setup lang="ts">
useCwaLayout()
</script>
No special props needed — the page content renders into the default <slot />.
Configuring a Layout
A layout declares its name in the admin, and the styles an admin can pick for it, with defineCwaConfig:
<!-- app/app/cwa/layouts/primary.vue -->
<script setup lang="ts">
defineCwaConfig({
name: 'Primary Layout',
styles: {
light: { label: 'Light', classes: 'theme-light' },
dark: { label: 'Dark', classes: 'theme-dark' },
},
})
useCwaLayout()
</script>
A layout can declare only name and styles. Each style has a key, which the layout stores as style:dark in uiClassNames, a label for the admin, and a class string. The admin adds a Default option with no classes, so don't declare one. The picked style's classes go on your layout's root element.
A layout without defineCwaConfig still renders. The admin names it by its component name without the CwaLayout prefix, such as Primary, and offers no styles. Component Files › Configuring a Component covers the macro's rules, which are the same for every kind of file.
Accessing Layout Data
useCwaLayout() gives you the layout resource and what it stores for the picked styles:
const cwa = useCwa()
const { layout, uiClassNames } = useCwaLayout()
const isLoading = computed(() => cwa.resources.isLoading.value)
uiClassNames holds one style:<key> entry for each style the admin picked. You don't bind it: the root layout puts those styles' classes on your layout's root element.
Component Groups
Add named component groups that admins can fill with components. The reference is a stable name unique within this layout's IRI:
<template>
<div>
<header>
<CwaComponentGroup
reference="navigation"
:location="$cwa.resources.layoutIri.value"
/>
</header>
<slot />
<footer>
<CwaComponentGroup
reference="footer"
:location="$cwa.resources.layoutIri.value"
/>
</footer>
</div>
</template>
location must be the IRI of the owning entity — for layout groups, that's $cwa.resources.layoutIri.value.
Auth-Conditional UI
$cwa.auth.signedIn and $cwa.auth.status come from a cookie, so you can render them on the server. isAdmin, user and roles need the user loaded, so wrap UI that reads them in <ClientOnly>:
<UserMenu v-if="$cwa.auth.signedIn.value" />
<NuxtLink v-else to="/login">Sign in</NuxtLink>
See Reading Auth State for the details.
Multiple Layouts
Create one file per layout variant. A common setup:
app/app/cwa/layouts/
primary.vue # full layout with header + footer
Minimal.vue # just a centered container (login pages, errors)
Landing.vue # marketing layout with large hero
Each file declares its own name and styles with defineCwaConfig.
Loading State
Show a skeleton while the layout resource is loading. The layout loads first in the CWA fetch sequence, so this is typically only visible on the initial server-side render:
<div v-if="$cwa.resources.isLoading.value" class="animate-pulse ...">
<!-- skeleton -->
</div>
<div v-else>
<!-- real content -->
</div>
Renaming or Deleting a Layout
A Layout resource stores the component name in uiComponent. Rename or delete the Vue file and that stored value dangles — it now points at a component the app no longer registers.
CWA falls back to the default layout and warns rather than failing, so one dangling value can't take the site down:
The layout component 'CwaLayoutPrimary' for resource '/_/layouts/018e-…' cannot be resolved
The same message appears as a warning on the layout's admin page at /_cwa/layouts/[iri], and the select keeps the unresolvable value as a clearly-marked option so you can see what is actually stored. That display is presentational only — nothing rewrites the resource. Fix it by picking a registered component in the admin.