Back to Directus

Explore Layouts

content/guides/09.extensions/3.app-extensions/3.layouts.md

latest6.5 KB
Original Source

Layouts allow for listing of items in :product-link{product="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.

:partial{content="extensions-app"}

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

js
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.

:partial{content="extensions-uid"}

Layout Component

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

Component Example

vue
<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.

:partial{content="extensions-app-internals"}