PHPackages                             winter/wn-blocks-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. winter/wn-blocks-plugin

ActiveWinter-plugin[Framework](/categories/framework)

winter/wn-blocks-plugin
=======================

Block based content management plugin for Winter CMS.

2612.7k↓25.6%5[3 PRs](https://github.com/wintercms/wn-blocks-plugin/pulls)1PHPCI passing

Since Aug 30Pushed 3mo ago6 watchersCompare

[ Source](https://github.com/wintercms/wn-blocks-plugin)[ Packagist](https://packagist.org/packages/winter/wn-blocks-plugin)[ RSS](/packages/winter-wn-blocks-plugin/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (1)

Blocks Plugin
=============

[](#blocks-plugin)

[![Blocks Plugin](https://github.com/wintercms/wn-blocks-plugin/raw/main/.github/banner.png?raw=true)](https://github.com/wintercms/wn-blocks-plugin/blob/main/.github/banner.png?raw=true)

[![MIT License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/wintercms/wn-blocks-plugin/blob/main/LICENSE)

Provides a "block based" content management experience in Winter CMS

> **NOTE:** This plugin is still in development and is likely to undergo changes. Do not use in production environments without using a version constraint in your composer.json file and carefully monitoring for breaking changes.

Installation
------------

[](#installation)

This plugin is available for installation via [Composer](http://getcomposer.org/).

```
composer require winter/wn-blocks-plugin
```

After installing the plugin you will need to run the migrations and (if you are using a [public folder](https://wintercms.com/docs/develop/docs/setup/configuration#using-a-public-folder)) [republish your public directory](https://wintercms.com/docs/develop/docs/console/setup-maintenance#mirror-public-files).

```
php artisan migrate
```

> **NOTE:** In order to have the `actions` support function correctly, you need to load `/plugins/winter/blocks/assets/dist/js/blocks.js` after the Snowboard framework has been loaded.

Core Concepts
-------------

[](#core-concepts)

### Blocks

[](#blocks)

This plugin manages the concept of "blocks" in Winter CMS. Blocks are self contained pieces of structured content that can be managed and rendered in a variety of ways.

Blocks can be provided by both plugins and themes and can be overridden by themes.

### Actions

[](#actions)

This plugin also introduces the concepts of "actions"; a way to define and execute client side actions that can be triggered by various events. Currently, actions are only defined in the `$/winter/blocks/meta/actions.yaml` file and must exist as a function on the `window.actions` object in the frontend keyed by the action's identifier that receives the `data` object as the first argument and (optionally) the `event` object that triggered the action as the second argument.

> **NOTE:** This is very much a WIP API and is subject to change. Feedback very much welcome here for ideas around how to register, manage, extend, and provide actions to the frontend.

### Tags

[](#tags)

Blocks may have one or more tags, which is a way of defining and grouping blocks. For example, you may have a Gallery block which allows only "image" tagged blocks to be used, or a container block which allows all "content" tagged blocks but does not allow another "container" tagged block within.

Tags are defined in the blocks, and can be used to filter the available blocks in the Blocks form widget.

Registering Blocks
------------------

[](#registering-blocks)

Themes can have their blocks automatically registered by placing `.block` files in the `/blocks` folder and subfolders.

Plugins can register blocks by providing a `registerBlocks()` method in their Plugin.php file. The method should return an array of block definitions in the following format:

```
public function registerBlocks(): array
{
    return [
        'example' => '$/myauthor/myplugin/blocks/example.block',
    ];
}
```

Block Definition
----------------

[](#block-definition)

Blocks are defined as `.block` files that consist of 2 to 3 parts:

- A YAML configuration section that defines the block's name, description, and other metadata as well as the block's properties and the form used to edit those properties.
- A PHP code section that allows for basic code to be executed when the block is rendered, similar to a partial.
- A Twig template section that defines the HTML markup template of the block.

When there are two parts, they are the Settings (YAML) &amp; Markup (Twig) sections.

The following property values (name, description, etc) can be defined in the Settings (YAML) section of the `.block` files:

```
name: Example
description: Example Block Description
icon: icon-name
tags: [] # Defines the tags that this block is associated with
permissions: [] # List of permissions required to interact with the block
fields: # The form fields used to populate the block's content
config: # The block configuration options
```

Blocks can use components in them, although they may face lifecycle limitations with complex AJAX handlers similar to component support in partials.

### Fields and Configuration

[](#fields-and-configuration)

Blocks may define both `fields` as well as a `config` property in the Settings. Both of these parameters accept a [form schema](https://wintercms.com/docs/backend/forms#form-fields), but serve different purposes. In general, `fields` should contain the fields that actually fill in the content of the block, whereas the `config` should contain the fields that define the appearance or structure of the block itself. Fields are displayed within the block in the `blocks` form widget and configuration is displayed in an Inspector which can be shown by clicking on the "cogwheel" icon of a block in the `blocks` form widget.

For example, let's say you have a **Title** block which can display a heading tag in your content. You may optionally want to align it to left, center or right, and define which heading tag to use. The best practice would be to have a `content` field in the `fields` definition, because it's the actual content being displayed. The `alignment` and `tag` would become part of the `config` configuration.

**Example:**

```
name: Title
description: Adds a title
icon: icon-heading
tags: ["content"]
fields:
    content:
        label: false
        span: full
        type: text
config:
    size:
        label: Size
        span: auto
        type: dropdown
        default: h2
        options:
            h1: H1
            h2: H2
            h3: H3
            h4: H4
            h5: H5
    alignment_x:
        label: Alignment
        span: auto
        type: dropdown
        default: center
        options:
            left: Left
            center: Centre
            right: Right
==
{% if config.alignment_x == 'left' %}
    {% set alignment = 'text-left' %}
{% elseif config.alignment_x == 'center' or not config.alignment_x %}
    {% set alignment = 'text-center' %}
{% elseif config.alignment_x == 'right' %}
    {% set alignment = 'text-right' %}
{% endif %}

    {{ content }}

```

Using the `blocks` FormWidget
-----------------------------

[](#using-the-blocks-formwidget)

In order to provide an interface for managing block-based content, this plugin provides the `blocks` FormWidget. This widget can be used in the backend as a form field to manage blocks.

The `blocks` FormWidget supports the following additional properties:

- `allow`: An array of block types that are allowed to be added to the widget. If specified, only those block types listed will be available to add to the current instance of the field. You can define either a straight array of individual blocks to allow, or define an object with `tags` and/or `blocks` to allow whole tags or individual blocks.
- `ignore`: A list of block types that are not allowed to be added to the widget. If not specified, all block types will be available to add to the current instance of the field. You can define either a straight array of individual blocks to ignore, or define an object with `tags` and/or `blocks` to ignore whole tags or individual blocks.
- `tags`: A list of block tags that are allowed to be added to the widget. If specified, only block types that have at least one of the listed tags will be available to add to the current instance of the field.

Those properties allow you to limit the block types that can be added to a specific instance of the widget, which can be very helpful when building "container" type blocks that need to avoid including themselves or only support a specific set of blocks as "children".

### Examples

[](#examples)

The `button_group` block type only allows a `button` block to be added to it:

```
buttons:
    label: Buttons
    span: full
    type: blocks
    allow:
        - button
```

The `container` block type allows any block called `title`, or has a tag of `content`, to be added to it:

```
container:
    label: Container
    span: full
    type: blocks
    allow:
        blocks:
            - title
        tags:
            - content
```

The `columns_two` block type allows every block except for itself to be added to it:

```
left:
    label: Left Column
    span: left
    type: blocks
    ignore:
        - columns_two
right:
    label: Right Column
    span: right
    type: blocks
    ignore:
        - columns_two
```

### Integration with the Winter.Pages plugin:

[](#integration-with-the-winterpages-plugin)

Include the following line in your layout file to include the blocks FormWidget on a Winter.Pages page:

```
{variable type="blocks" name="blocks" tags="pages" tab="winter.pages::lang.editor.content"}{/variable}
```

Rendering Blocks
----------------

[](#rendering-blocks)

### Using Twig

[](#using-twig)

Twig functions are provided by this plugin for rendering blocks. You can then use the following Twig snippet to render the blocks data in your layout:

```
{{ renderBlocks(blocks) }}
```

You can use it anywhere an expression is accepted:

```
{{ ('Some text' ~ renderBlocks(blocks) ~ 'Some more text') | raw }}

{% set myContent = renderBlocks(blocks) %}
```

If you need to render a single block, you can use the `renderBlock` function:

```
{{ renderBlock({
    '_group':'title',
    'content':'Lorem ipsum dolor sit amet.',
    'alignment_x':'left',
    'size':'h1',
}) }}

{{ renderBlock('title', {
    'content':'Lorem ipsum dolor sit amet.',
    'alignment_x':'left',
    'size':'h1',
}) }}
```

### Using a partial

[](#using-a-partial)

If you need to customize the rendering of blocks according to their group, you can use a special `blocks.htm` partial in your theme:

```
{% for blockIndex, block in blocks %}
    {# Adding blocks to the following array allows them to implement their own containers #}
    {% if block._group in ["hero", "section"] %}
        {{ renderBlock(block) }}
    {% else %}

                {{ renderBlock(block) }}

    {% endif %}
{% endfor %}
```

You can then use the following Twig snippet to render the block data in your layout:

```
{% partial 'blocks' blocks=blocks %}
```

### Using PHP

[](#using-php)

```
use Winter\Blocks\Classes\Block;

// Render a single block from stored data
Block::render($model->blocks[0]);

// Render an array of blocks from stored data
Block::renderAll($model->blocks);

// Render a single block manually
Block::render('title', [
    'content' => 'Lorem ipsum dolor sit amet.',
    'alignment_x' => 'left',
    'size' => 'h1',
]);

// Render a single block manually using only array data
Block::render([
    '_group' => 'title',
    'content' => 'Lorem ipsum dolor sit amet.',
    'alignment_x' => 'left',
    'size' => 'h1',
]);
```

Integrating with TailwindCSS / CSS Purging
------------------------------------------

[](#integrating-with-tailwindcss--css-purging)

If your theme uses CSS class purging (i.e. Tailwind), it can be useful to add the following paths to your build configuration to include the styles for any blocks defined by the theme or plugins.

```
// tailwind.config.js
module.exports = {
    content: [
        // Winter.Pages static page content
        './content/**/*.htm',
        './layouts/**/*.htm',
        './pages/**/*.htm',
        './partials/**/*.htm',
        './blocks/**/*.block',

        // Blocks provided by plugins
        '../../plugins/*/*/blocks/*.block',
    ],
};
```

Feedback
--------

[](#feedback)

> The Winter.Blocks is perfect for my block-based themes. I've been looking for something like this for a long time

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance55

Moderate activity, may be stable

Popularity37

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7253840?v=4)[Luke Towers](/maintainers/LukeTowers)[@LukeTowers](https://github.com/LukeTowers)

---

Top Contributors

[![bennothommo](https://avatars.githubusercontent.com/u/15900351?v=4)](https://github.com/bennothommo "bennothommo (32 commits)")[![LukeTowers](https://avatars.githubusercontent.com/u/7253840?v=4)](https://github.com/LukeTowers "LukeTowers (32 commits)")[![damsfx](https://avatars.githubusercontent.com/u/282242?v=4)](https://github.com/damsfx "damsfx (13 commits)")[![mjauvin](https://avatars.githubusercontent.com/u/2013630?v=4)](https://github.com/mjauvin "mjauvin (4 commits)")[![jaxwilko](https://avatars.githubusercontent.com/u/31214002?v=4)](https://github.com/jaxwilko "jaxwilko (3 commits)")[![helmutkaufmann](https://avatars.githubusercontent.com/u/5102490?v=4)](https://github.com/helmutkaufmann "helmutkaufmann (1 commits)")

---

Tags

blockshacktoberfestlaravelwintercms

### Embed Badge

![Health badge](/badges/winter-wn-blocks-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/winter-wn-blocks-plugin/health.svg)](https://phpackages.com/packages/winter-wn-blocks-plugin)
```

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

712181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[laravel/pail

Easily delve into your Laravel application's log files directly from the command line.

91545.3M590](/packages/laravel-pail)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
