Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Add a block type

Create a new block type editors can drag into any layout - a block definition in explayouts.ini, an existing or new handler class, and a template - with where AvailableBlocks[] is read and a tested example, the Notice…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/build-two-ways/add-a-block-type.md

On this page

Add a block type

A block type has three parts: a definition in explayouts.ini, a handler class that declares its parameters, and a template per design. The example is a Notice block: a short text in a highlighted box, in two view types, info and warning. It reuses an existing handler, so no PHP is written.

Contents

  1. The definition
  2. The handler
  3. The template
  4. Activate, clear, find it in the palette
  5. Use it
  6. Your own handler

1. The definition

extension/mysite/settings/explayouts.ini.append.php:

<?php /* #?ini charset="utf-8"?

[BlockSettings]
AvailableBlocks[]=notice

# A new block type: a highlighted notice with a text an editor types
[BlockDefinition_notice]
Name=Notice
Handler=expLayoutsTextBlockHandler
ViewTypes[]=info
ViewTypes[]=warning
Category=basic

*/ ?>
KeyMeans
AvailableBlocks[]the block types the editor offers
Namethe name in the palette and on the block
Handlerthe PHP class that declares the parameters
ViewTypes[]the looks an editor can choose on the Design tab
Categorythe palette group: basic, components, listing, gallery, containers, placeholders
HasCollection=1the block has items (like List)
IsContainer=1 and Placeholders[]the block holds other blocks (like Column)

Where the line counts. Since explayouts 1.4.42, explayouts' own explayouts.ini.append.php no longer starts AvailableBlocks[] (nor AvailableQueries[], SiteAccessMatch[] and AllowedTemplateRoots[]) with a reset line. Your extension's AvailableBlocks[]=notice is kept wherever the extension is listed in ActiveExtensions[]: for blocks the position no longer matters, and a block listed twice is offered once (./console exp:ini where explayouts.ini/BlockSettings/AvailableBlocks admin shows the list in effect). To replace the whole list, write the reset line where it is read after every extension: settings/override/explayouts.ini.append.php or a siteaccess (./console exp:ini clear explayouts.ini/BlockSettings/AvailableBlocks[] <scope>). The extension order still matters for template overrides and DesignExtensions[] (Your own design extension).

2. The handler

expLayoutsTextBlockHandler declares one parameter:

'content' => array( 'name' => 'Content', 'type' => 'textarea', 'default' => '' ),

The editor builds the block's form from the handler's getParameters(); the field appears on the Design tab.

3. The template

The media design includes explayouts/block/<definition>.tpl for every block, so the template is extension/mysite/design/media/templates/explayouts/block/notice.tpl:

{if and( is_set( $block.parameters.content ), $block.parameters.content|ne( '' ) )}
<aside class="notice notice-{$block.view_type|wash}" role="note">
    <p>{$block.parameters.content|wash|nl2br}</p>
</aside>
{/if}

The design's block.tpl wraps it in <div class="ngl-block ngl-notice ngl-vt-<view type> ..."> and applies the common options (spacing, CSS class, container).

4. Activate, clear, find it in the palette

./console exp:cache clear --tag=template,content,ini

Open a layout in the editor and the palette's Basic group has Notice:

The block palette: the Basic group ends with Notice
The block palette: the Basic group ends with Notice

5. Use it

The Notice block dropped into the Prefooter, still without content
The Notice block dropped into the Prefooter, still without content

Drag Notice into a zone. It arrives with the view type default; select it, open Design, choose warning, type the text into Content, and Publish layout.

The Notice block on the Design tab: View type warning and the Content text
The Notice block on the Design tab: View type warning and the Content text

The published page renders:

<div class="ngl-block ngl-notice ngl-vt-warning whitespace-top-none whitespace-bottom-none">
  <div class="container">
    <aside class="notice notice-warning" role="note"><p>Prices of the training plans change on 1 November.</p></aside>
  </div>
</div>
The notice text under the Most popular articles band, not styled yet
The notice text under the Most popular articles band, not styled yet

It is plain until the design styles .notice (Styling your blocks).

Your own handler

For other fields, write a class that implements expLayoutsBlockHandlerInterface with getParameters() (the fields: name, type, default) and getValues( $block ) (what the template gets in $block.values), put it in extension/mysite/classes/, run php bin/php/ezpgenerateautoloads.php -e, and name it in Handler=. The handlers of extension/explayouts/classes/ (for example explayoutstextblockhandler.php, explayoutstplblockhandler.php) are short examples.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x