Back to Directus

Inline Displays

content/guides/09.extensions/3.app-extensions/2.displays.md

latest5.2 KB
Original Source

Displays are small components that are used to display a single value throughout the Data Studio.

Displays receive a single value and any custom display options that are defined in the display entrypoint. They are then expected to render the value in a user-friendly way.

:partial{content="extensions-app"}

Display Entrypoint

The index.js or index.ts file exports an object that is read by Directus. It contains properties that control how a display is displayed throughout the Data Studio, which options are available, and the actual Vue component that will be loaded.

Entrypoint Example

js
import { defineInterface } from '@directus/extensions-sdk'
import DisplayComponent from './display.vue';

export default defineInterface({
	id: 'custom',
	name: 'Custom',
	icon: 'box',
	description: 'This is my custom display!',
	component: DisplayComponent,
	options: null,
	types: ['string'],
});

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.
descriptionstringA description of this display shown in the Data Studio. Maximum 80 characters.
componentcomponentA reference to your display component.
optionsobject | componentThe options of your display. Can be either an options object or a dedicated Vue component.
typesarrayAll types supported by the display.
localTypesarrayAll local types supported by this display. Accepts standard, file, files, m2o, o2m, m2m, m2a, presentation, translations and group. Defaults to standard.
fieldsarray | functionIf this option is set, the display will fetch relational fields. Can either be an array of fields or a function that returns an array of fields.

:partial{content="extensions-uid"}

Display Component

The display component is a Vue component that will be rendered in the Data Studio whenever your display is used to show the value of a field. Data from the entrypoint are passed in as props.

Component Example

This example assumes there is an item in the entrypoint’s options array with a field value of url.

vue
<template>
	<div>Value: {{ value }}</div>
</template>

<script>
export default {
	props: {
		value: {
			type: String,
			default: null,
		},
	},
};
</script>

The current value of the field is provided to the component via the value prop. If you use the fields option to fetch relational fields, the value prop will be an object with the requested fields as keys and their respective values.

Props

PropTypeDescription
valueanyThe value of the field.
interfacestringThe interface of the field.
interfaceOptionsobjectThe options for the field's interface.
typestringThe type of the field.
collectionstringThe collection name of the field.
fieldstringThe key of the field.

Functional Component

Instead of defining the component inside a separate Vue file, you can use a functional component. This allows you to make small displays that don't need a full component.

js
import { defineInterface } from '@directus/extensions-sdk'

export default defineInterface({
	id: 'custom',
	name: 'Custom',
	icon: 'box',
	description: 'This is my custom display!',
	component: function ({ value }) {
		return value.toLowerCase();
	},
	options: null,
	types: ['string'],
});

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