Skip to content

Component resolution

Druxt finds a wrapper component by ranking candidate names from the render context, then hands it the props, slots and attributes it needs.

Every Druxt component (entities, fields, menus, views, blocks) delegates its rendering to a wrapper component. The wrapper is found, not specified: Druxt builds a ranked list of candidate names from the render context and uses the most specific one that exists in your project. This is Druxt's theming model, and it's why the framework is unstyled by design: the styling is your components, discovered by its rules.

The suggestion chain

A DruxtEntity rendering an article in the teaser mode generates candidates in this order (most specific first):

DruxtEntityNodeArticleTeaserView
DruxtEntityNodeTeaserView
DruxtEntityNodeArticleTeaser
DruxtEntityNodeTeaser
DruxtEntityNodeArticle
DruxtEntityNode
DruxtEntityTeaser

Bare DruxtEntity is never a candidate. The first candidate that exists as a component in your project wins. If none match, Druxt renders through its own DruxtWrapper. Exists means discovered by Nuxt's auto-import from your components/ directory, so a saved file is immediately a candidate.

The last part, View, is the schema type. It is View for a display and Form for a form, as in DruxtEntityNodeArticleTeaserForm. See Display schemas.

When a language is in play, each candidate also gets a variant with the langcode added, such as DruxtEntityNodeArticleTeaserEs. Each name is built from parts, one per value in the render context, and the resource type node--article is one part, NodeArticle. The langcode counts as one more part. DruxtEntityNodeArticleTeaserEs has three parts (NodeArticle, Teaser, Es), and ranks with the other three-part names, such as DruxtEntityNodeArticleTeaserView. In Spanish, the list starts:

DruxtEntityNodeArticleTeaserViewEs
DruxtEntityNodeTeaserViewEs
DruxtEntityNodeArticleTeaserEs
DruxtEntityNodeArticleTeaserView
DruxtEntityNodeTeaserEs
DruxtEntityNodeTeaserView

Where candidates come from

Each module built on the DruxtModule base class provides a druxt.componentOptions() callback returning sets of name parts. The base class turns the parts into PascalCase candidate names, adds language variants, de-duplicates, and sorts most-specific first. The order in the sorted list is the theme override order: more parts (a more precise context) beats fewer.

DruxtEntity provides these sets of parts:

  • The resource type, view mode and schema type.
  • The entity type, view mode and schema type.
  • The view mode alone.

Each set gives one name per prefix, so node--article, teaser and view give DruxtEntityNodeArticle, DruxtEntityNodeArticleTeaser and DruxtEntityNodeArticleTeaserView. Because node--article is one part, DruxtEntityNodeTeaserView (three parts) ranks above DruxtEntityNodeArticleTeaser (two). When two names have the same number of parts, the order of the sets decides: the bundle's name (NodeArticle, the content type) comes before the entity type's (Node).

The chain is visible at development time: the resolved options live on the component's component.options data, and the Vue Devtools integration can print a ready-to-edit skeleton for the component it would have used.

In development, a Druxt component can show a "Missing default slot" box in the page. It appears when the component has no default content to render: its module doesn't provide any, and you don't put markup between its tags (a default template). When no wrapper matched, the box lists the candidate names, with the data a wrapper would receive. It is a different box from the "Missing Vue template" box that DruxtBlock and DruxtField show, which Theme Druxt components describes.

How wrappers receive data

A resolved wrapper isn't a slot dump: it's a full component with an input contract:

  • propsData: the module's druxt.propsData() callback maps its data to props the wrapper declares (an entity wrapper receives entity, a field wrapper receives the field data and schema settings).
  • Slots: the module's druxt.slots() render functions provide default content, which the wrapper places and wraps as it sees fit.
  • $attrs: any module data the wrapper does not declare as a prop arrives on $attrs. Vue renders it onto the root element as HTML attributes unless the wrapper sets inheritAttrs: false, as the example below does. (class and style are never part of $attrs in Vue 2.)

A minimal wrapper is tiny:

<!-- components/druxt/entity/node/article/Teaser.vue -->
<template>
  <article class="prose">
    <slot name="field_image" />
    <slot />
  </article>
</template>

<script>
export default {
  inheritAttrs: false,
  props: { entity: { type: Object, default: undefined } },
};
</script>

Drop that file in your project and it takes over article teaser rendering everywhere, with nothing to register and no framework code to copy. The directory path is what Nuxt auto-discovery turns into the candidate name (druxt/entity/node/article/Teaser.vue → DruxtEntityNodeArticleTeaser); the entity prop and per-field scoped slots (field_image, and one per rendered field) are what the module feeds you.

Re-wrapping at the point of use

Separately from the suggestion system, any Druxt component accepts a wrapper prop that swaps the element wrapping its output:

<DruxtEntity type="node--article" :uuid="uuid" :wrapper="{ component: 'b', class: 'title' }" />

This composes with the theme layer: the wrapper component is resolved by suggestions, then wrapped again by whatever you passed.

Why this design

The common failure it avoids is the fork: a theming system that requires editing framework components (or copying them) makes upgrades painful and drift inevitable. Suggestion-based discovery means the framework never needs to know about your components: it only needs to name what it would like to see. The cost is indirection: the rendered component isn't visible at the use site, so the devtools integration and the component.options introspection exist to show you which component was chosen.