Drupal is a registered trademark of Dries Buytaert
Release: Drupal 10.3.6 Update released for Drupal core (10.3.6)! Release: Drupal 11.0.5 Update released for Drupal core (11.0.5)! Release: Drupal 10.2.9 Update released for Drupal core (10.2.9)! Release: Drupal 10.2.10 Update released for Drupal core (10.2.10)! Release: Drupal 10.3.7 Update released for Drupal core (10.3.7)! Release: Drupal 11.0.6 Update released for Drupal core (11.0.6)! Release: Drupal 10.3.8 Update released for Drupal core (10.3.8)! Release: Drupal 11.0.7 Update released for Drupal core (11.0.7)! Module Revived: Translation Management Tool 8.x-1.19 Module tmgmt updated after 7 months of inactivity (8.x-1.19). Usage Milestone: Account field split Module account_field_split crossed 10,000 active installs.

The Single File Components module allows developers to provide frontend components in a single file. These components contain Twig, CSS, JS, and PHP code which acts similar to a preprocess function.

The purpose of this module is to combine traditional Drupal theming with some elements of component based design.

Example code

Excited, confused, scared, and want to skip to some example code? Check out the documented files by clicking here!

Feature highlights

  • Put your Twig, CSS, JS, and PHP in one file, then use it like any other template (i.e. {% include "sfc--say-hello.html.twig" %}). Components can be defined as PHP classes or .vue style .sfc files. (link)
  • Library definitions are automatically generated and included in your template, saving developer time
  • Easily override components in themes by replacing library definitions and overriding their templates (link)
  • Save time by writing JS in the ATTACH constant, which automatically wraps your code in a Drupal behavior and a jQuery.once call (link)
  • Derive blocks, layouts, and field formatters from components using annotations (link)
  • Provide backend actions without writing a route or controller(link)
  • Single file components are Drupal plugins, you can extend them, derive them, and alter their plugin definition. You also have access to dependency injection so components can be unit tested.
  • Component library available at /sfc/library for developers to stress test and play with components. (link)

Requirements

PHP 7+ is required if you're defining the LIBRARY or DEPENDENCIES constants.

Installation

This module has no dependencies, so to install it, download and install it!

Writing a component

The README.md file is the best place to look for technical documentation, but you can also check out the sfc_example sub-module for example plugins.

Sites built with Single File Components

Slack channel

Join me in Slack in the #single-file-components channel! Details on how to connect here: https://www.drupal.org/slack

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Nov 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Core Release date
8.x-1.12 Stable Nov 23, 2024