App Extensions

Explore Layouts

Layouts are used to display a list of items in Explore pages in different ways.

Layouts allow for listing of items in Explore pages.

Layouts receive a collection, filters, searches, and any custom layout options that are defined in the layout entrypoint. They are then expected to fetch and render the items from a collection.

A table display in the content module

This extension type is loaded into the Directus Data Studio. They are are built with Vue 3, and can use the provided composables exported by the @directus/extensions-sdk package. Extensions can be written in JavaScript or TypeScript.

Layout Entrypoint

The index.js or index.ts file exports an object that is read by Directus. It contains properties that control how a layout is displayed within menus, which options are available, optional slots, and the actual Vue component that will be loaded.

Entrypoint Example

import { ref } from 'vue';
import { defineInterface } from '@directus/extensions-sdk'
import LayoutComponent from './layout.vue';

export default defineInterface({
    id: 'custom',
    name: 'Custom',
    icon: 'box',
    component: LayoutComponent,
    slots: {
        options: () => null,
        sidebar: () => null,
        actions: () => null,
    },
    setup() {
        const name = ref('Custom Layout');
        return { name };
    },
});

Properties

PropertyTypeDescription
idstringA unique identifier for this extension.
namestringThe displayed name for this layout in the Data Studio.
iconstringAn icon name from the Google Material Icons set. Supports filled and outlined variants.
componentcomponentA reference to the Vue component rendered in the Explore page.
slotsobjectAdditional components to be added by your layout.
slots.optionscomponentA reference to an options component.
slots.sidebarcomponentA reference to a sidebar component.
slots.actionscomponentA reference to an actions component.
setupfunctionA function to setup reactive state to be shared by the layout component and the other components. It receives a props object as the first parameter and a context object containing an emit() function as the second parameter.

The actions slot is used to render additional buttons at the top of the layout by the search bar. It is commonly used to add additional buttons or display metadata about the layout.

Unique Identifiers
The extension id must not conflict with other extensions, so consider prefixing with author name.

Layout Component

The layout component is a Vue component that will be rendered in the Data Studio within Explore pages.

Component Example

<template>
    <div>
        <p>Name: {{ name }}</p>
        <p>Collection: {{ collection }}</p>
    </div>
</template>

<script>
export default {
    inheritAttrs: false,
    props: {
        collection: {
            type: String,
            required: true,
        },
        name: {
            type: String,
            required: true,
        },
    },
};
</script>

Props

The layout component will be passed all user configuration options from the entrypoint file. It will also receive the following props:

PropTypeDescription
collectionstringThe current collection's name.
selectionarrayAny currently selected items.
layoutOptionsobjectThe user's currently saved layout options.
layoutQueryobjectThe user's layout query parameters. (e.g., sort, limit, etc).
filterobjectThe combined active filter.
filterUserobjectThe user's currently active filter.
filterSystemobjectThe system's currently active filter.
searchstringThe user's current search query.
selectModebooleanIndicates if the layout should be in select mode.
readonlybooleanIndicates if the layout should be in readonly mode.
resetPresetfunctionA function to reset the preset.

Emits

The layout component can emit the following events that will be recognized by Directus.

EventDescription
update:selectionUpdate the currently selected items.
update:layoutOptionsUpdate the user's currently saved layout options.
update:layoutQueryUpdate the user's layout query parameters.

Using Directus Internals

To access internal systems like the API or the stores in app extensions, you can use the useApi() and useStores() composables exported by the @directus/extensions-sdk package.

Learn more about using Directus composables.

Directus UI components are globally registered, making them accessible throughout your extension without the need to import them.

Learn more about using the Directus UI library.

Using External APIs

To avoid Cross Site Request Forgery (CSRF), app extensions cannot make requests to external servers by default. A common approach to achieve this is to create a bundle containing an endpoint that makes the external request, and an app extension that uses the now-internal endpoint to retrieve data.

Learn more about building extensions through our tutorials.