useCwaLayout
The composable for CWA layout files. It returns the active layout resource and the raw uiClassNames stored on it.
const { layout } = useCwaLayout()
Signature
useCwaLayout()
It takes no options.
Return Values
| Return | Type | Purpose |
|---|---|---|
layout | ComputedRef<CwaCurrentResourceInterface | undefined> | The active layout resource. Its fields are on .value?.data |
uiClassNames | ComputedRef<string[] | undefined> | What the layout stores: one style:<key> entry for each style an admin picked |
Example
<template>
<div>
<header>
<CwaComponentGroup reference="nav" :location="$cwa.resources.layoutIri.value" />
</header>
<main><slot /></main>
</div>
</template>
<script setup lang="ts">
defineCwaConfig({
name: 'Primary Layout',
styles: {
'blue-bg': { label: 'Blue Background', classes: 'bg-blue-600' },
},
})
const { layout } = useCwaLayout()
</script>
The layout's styles are declared with defineCwaConfig in the same file; see Layouts › Configuring a Layout. The root layout puts the picked styles' classes on your layout's root element, so you don't bind them.
Styling an Inner Element
The classes always go on the root element. To style an inner element by the picked style, read the stored keys:
<template>
<div>
<main :class="{ 'max-w-none': wide }"><slot /></main>
</div>
</template>
<script setup lang="ts">
const { uiClassNames } = useCwaLayout()
const wide = computed(() => !!uiClassNames.value?.includes('style:wide'))
</script>
Accessing Layout Data
const { layout } = useCwaLayout()
// layout.value?.data holds the layout entity fields
const reference = computed(() => layout.value?.data?.reference)
See Your First Layout for the full setup guide.
Overview
Which CWA composable to use for a layout, a display component, a form, an admin tab, an auth page or a utility.
Component (recommended)
The recommended entry point for all CWA display components — fetch resource data, expose to the admin manager, and compose plugins for collections, uploaded files, or custom behaviour.