Skip to content

Blocks

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

DruxtBlocks renders Drupal blocks and block regions in Nuxt

npm CI Known Vulnerabilities codecov

DruxtBlocks brings Drupal's block layout to Nuxt. DruxtBlockRegion renders every visible block Drupal places in a theme region, and DruxtBlock renders one block anywhere in your layout. Both resolve through the Druxt component suggestion system, so overriding one block's markup takes one Vue component.

Example DruxtBlockRegion component

Features

  • Vue.js components:
    • DruxtBlock renders Drupal blocks by UUID or internal ID
    • DruxtBlockRegion renders all blocks within a region
  • Druxt settings filter JSON:API fields
  • @nuxtjs/Storybook integration

Installation

Included with druxt-site. Install it separately only when composing modules yourself.

  1. Install the package:

    npm i druxt-blocks
    
  2. Add the module to nuxt.config.js:

    export default {
      modules: ['druxt-blocks'],
    };
    

Development releases

Every change merged to develop is published under the dev tag:

npm i druxt-blocks@dev

These are unreleased builds. See development releases before using one.

Vue.js components

DruxtBlock

Renders a Drupal Block by UUID or Drupal's internal ID.

<DruxtBlock :id="drupal_internal__id" />
<DruxtBlock :uuid="uuid" />

DruxtBlockRegion

Renders all visible blocks by theme and region name.

<DruxtBlockRegion :name="name" :theme="theme" />

Settings

Reducing Block data

The default behaviour of the Block module is to retrieve all available fields from the JSON:API.

This behaviour is configurable using the modules query option, allowing for manually filtered fields.

The default behaviour can be set via nuxt.config.js:

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

Storybook

DruxtBlocks provides zero-config, auto-generated Storybook integration with a live data connection to your Druxt backend.

DruxtBlocks Storybook integration


Options

DruxtBlock options

These options are specific to this module.

OptionTypeRequiredDefaultDescription
blocks.query.fieldsstring[]No[]An array of fields to filter all Block JSON:API queries.

Base Druxt options

These options are available to all Druxt modules.

OptionTypeRequiredDefaultDescription
axiosobjectNo{}Axios instance settings.
baseUrlstringYesnullBase URL for the Drupal installation.
endpointstringNo/jsonapiJSON:API Endpoint of the Drupal installation.

Note: The contents of this file were automatically generated from the packages/blocks/README.md.

Try it

Live
resolving

Props live: every change re-renders above

uuid

string

nothing to choose on this backend

langcode

string

one language on this backend

value

object

set in code

wrapper

boolean, true

<DruxtBlock />