Skip to content

Render Drupal blocks and block regions in Nuxt with the druxt-blocks components, themed through the Druxt component suggestion system.

DruxtBlock

View source on GitHub

DruxtBlock

The DruxtBlock component renders a Drupal Block by UUID or by its block placement machine name.

While the DruxtBlock component can't automatically render every Drupal block, it does provide the Block settings to a targeted Druxt wrapper component for manual theming.

See

Example (Render a block using id)

<DruxtBlock id="umami_branding" />

Example (Render a block using uuid)

<DruxtBlock uuid="59104acd-88e1-43c3-bd5f-35800f206394" />

Example (DruxtBlock Wrapper component boilerplate)

<template>
  <DruxtDebug :json="block" />
</template>

<script>
import { DruxtBlocksBlockMixin } from 'druxt-blocks'
export default {
  mixins: [DruxtBlocksBlockMixin]
}
</script>

Example (DruxtBlock default slot (template injection))

<DruxtBlock id="umami_branding">
  <template #default="{ block }">
    <!-- Do whatever you want here -->
    <DruxtDebug :json="block" />
  </template>
</DruxtBlock>

.props

The DruxtBlock component requires either the uuid or id property.

Kind: static property of DruxtBlock


.id : string

The block placement machine name, as configured on Drupal's Block layout page (/admin/structure/block).

Kind: static property of props
Default: "null"
Example

<DruxtBlock id="umami_branding" />

.uuid : string

The Block Entity UUID.

If used, the id prop will be ignored.

Kind: static property of props
Default: "null"
Example

<DruxtBlock uuid="59104acd-88e1-43c3-bd5f-35800f206394" />

.langcode : string

The resource langcode.

Kind: static property of props
Example

@lang vue
<DruxtBlock langcode="en" />

.v-model : mixed

The Vue.js v-model binding for the module.

Setting a value provides the module data directly, so the Drupal JSON:API fetch is skipped.

Kind: static property of props
Default:
Example

@lang vue
<template>
  <DruxtBlock v-model="model" />
</template>

<script>
export default {
  data: () => ({ model: { foo: 'bar' } })
}
</script>

.wrapper : (boolean | object)

The wrapper component configuration.

Used to set the wrapper component, class, style and propsData.

Kind: static property of props
Default: () => undefined
Example

<DruxtBlock
  :wrapper="{
    component: 'BCard',
    class: 'article-card',
    propsData: { noBody: true }
  }"
/>

.computed

Kind: static property of DruxtBlock


.block ⇒ object

The Block entity data.

Kind: static property of computed
Returns: object - The Block entity JSON:API resource data.

ParamTypeDescription
vmobjectThe component ViewModel.
vm.resourceobjectThe Block JSON:API resource.

.druxt

Druxt module configuration.

Kind: static property of DruxtBlock


.template

Druxt development template tool configuration.

Kind: static property of druxt


.componentOptions(context) ⇒ ComponentOptions

Provides the available component naming options for the DruxtWrapper.

Kind: static method of druxt

ParamTypeDescription
contextobjectThe module component ViewModel.
context.blockobjectThe Block entity data.

.fetchConfig()

Fetches the Block JSON:API resource by either UUID or ID.

Kind: static method of druxt


.propsData(context) ⇒ PropsData

Provides propsData for the DruxtWrapper.

Kind: static method of druxt

ParamTypeDescription
contextobjectThe module component ViewModel.
context.blockobjectThe Block entity data.

.slots(h) ⇒ ScopedSlots

Provides the scoped slots object for the Module render function.

A default slot is provided with debug information if Nuxt is in development mode.

Kind: static method of druxt
Returns: ScopedSlots - The Scoped slots object.

ParamTypeDescription
hfunctionThe Vue createElement function.

.data()

Provides the fetched Block resource state.

Kind: static method of DruxtBlock
Properties

NameTypeDescription
resourceobjectThe JSON:API resource object.

.methods

Kind: static property of DruxtBlock


.fetch()

Loads the Druxt module data and applies a wrapper component as required.

Important: If your component has an existing fetch method, you must manually invoke the DruxtModule.fetch() hook.

Kind: static method of DruxtBlock
Example (Manually invoking DruxtModule.fetch().)

import DruxtModule from 'druxt/components/DruxtModule.vue'
export default {
  name: 'DruxtCustomModule',
  extends: DruxtModule,
  async fetch() {
    await DruxtModule.fetch.call(this)
  },
  druxt: {
    componentOptions: () => ([['Default']]),
    propsData: ({ model }) => ({ value: model }),
  }
}

.lang(vm) ⇒ string

The current language code: the langcode prop if set, otherwise the route's langcode metadata.

Used by Druxt modules to fetch the correct resource translation.

Kind: static method of DruxtBlock
Returns: string - The current language code.

ParamTypeDescription
vmobjectThe component ViewModel.
vm.langcodestringThe langcode prop.
vm.$routeobjectThe current route.

.error(err, [context])

Sets the component to render a DruxtDebug error message.

Kind: instance method of DruxtBlock

ParamTypeDescription
errobjectThe error object.
[context]objectError context; carries the wrapper component data where the failure knows it.

.getModuleComponents() ⇒ Components

Get list of module wrapper components.

Kind: instance method of DruxtBlock


.getModulePropsData(wrapperProps) ⇒ object

Get module propsData via modules druxt.propsData() callback.

Kind: instance method of DruxtBlock

ParamTypeDescription
wrapperPropsobjectProps registered by the Wrapper component.

Example

{
  $attrs: { entity: {}, fields: {}, langcode: 'en', schema: {} },
  props: { value: {} },
  propsData: { entity: {}, fields: {}, langcode: 'en', schema: {}, value: {} },
}

.getScopedSlots() ⇒ object

Gets a Druxt modules scoped slots, and if there's no default slots, provides a develop mode debug default or passes through to a default template.

Kind: instance method of DruxtBlock


.getWrapperData(component) ⇒ WrapperData

Get wrapper component data.

Kind: instance method of DruxtBlock

ParamTypeDescription
componentstringThe Wrapper component name.

ComponentOptions : Array.<array>

Provides the available naming options for the Wrapper component.

Kind: global typedef
See: Component resolution
Example

[
  'DruxtBlock[Plugin][PluginId][Region][Theme][Langcode]',
  'DruxtBlock[Plugin][PluginId][Region][Theme]',
  'DruxtBlock[Plugin][PluginId][Theme][Langcode]',
  'DruxtBlock[Plugin][PluginId][Theme]',
  'DruxtBlock[Plugin][Region][Theme][Langcode]',
  'DruxtBlock[Plugin][Region][Theme]',
  'DruxtBlock[Plugin][Theme][Langcode]',
  'DruxtBlock[Plugin][Theme]',
  'DruxtBlock[Default][Langcode]',
  'DruxtBlock[Default]',
]

Example (Umami Branding block)

[
  'DruxtBlockSystemBrandingBlockHeaderUmamiEn',
  'DruxtBlockSystemBrandingBlockHeaderUmami',
  'DruxtBlockSystemBrandingBlockHeaderEn',
  'DruxtBlockSystemBrandingBlockHeader',
  'DruxtBlockSystemBrandingBlockUmamiEn',
  'DruxtBlockSystemBrandingBlockUmami',
  'DruxtBlockSystemBrandingBlockEn',
  'DruxtBlockSystemBrandingBlock',
  'DruxtBlockDefaultEn',
  'DruxtBlockDefault',
]

ModuleSettings : object

Provides settings for the Blocks module, via the nuxt.config.js druxt.blocks object.

Kind: global typedef

ParamTypeDescription
fieldsArray.<string>An array of fields to filter from the JSON:API Resource.

Example

{
  fields: [],
}

Example (nuxt.config.js)

export default {
  druxt: {
    blocks: {
      query: {
        fields: ['dependencies'],
      },
    },
  },
}

PropsData : object

Provides propsData for use in the Wrapper component.

Kind: global typedef

ParamTypeDescription
blockobjectThe Block Entity data.

Example

{
  block: {
    attributes: {},
    id: '59104acd-88e1-43c3-bd5f-35800f206394',
    links: {},
    relationships: {},
    type: 'block--block',
  },
}

ScopedSlots : object

Provides scoped slots for use in the Wrapper component.

Kind: global typedef

ParamTypeDescription
defaultfunctionDebug information if Nuxt is in development mode.

Inherited type definitions

Inherited from DruxtModule: ComponentData, Components, WrapperData.