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
Layout

useCwaLayout

Access the current layout resource and the style keys stored on it.

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

ReturnTypePurpose
layoutComputedRef<CwaCurrentResourceInterface | undefined>The active layout resource. Its fields are on .value?.data
uiClassNamesComputedRef<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.