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 view type

Give an existing block type a new look that editors can choose per block - one INI line and one template in your design extension. Worked example list_compact for the List block, from the INI to the editor's Design tab…

Download as PDF

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

On this page

Add a view type

A view type is one look of a block type. The List block offers list, grid, list_numbered, list_zigzag, list_accordion and grid_featured. This page adds a seventh, list_compact: a plain list of links with dates.

Contents

  1. Declare it
  2. Write its template
  3. Clear the caches
  4. Choose it in the editor
  5. The result

1. Declare it

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

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

# A new view type for the List block: a compact list of links
[BlockDefinition_list]
ViewTypes[]=list_compact

*/ ?>

Without a reset line (ViewTypes[] alone) the value is added to the six view types of extension/explayouts/settings/explayouts.ini.append.php. Check it:

$ ./console exp:ini where explayouts.ini/BlockDefinition_list/ViewTypes site
...
In effect:
      ViewTypes[]=list_compact
      ViewTypes[]=list
      ViewTypes[]=grid
      ViewTypes[]=list_numbered
      ViewTypes[]=list_zigzag
      ViewTypes[]=list_accordion
      ViewTypes[]=grid_featured

2. Write its template

The media design renders a List block with explayouts/block/list.tpl, which includes explayouts/block/list/<view type>.tpl. So the new template is extension/mysite/design/media/templates/explayouts/block/list/list_compact.tpl:

{if $block.values.items|count|gt( 0 )}
<ul class="list-compact">
{foreach $block.values.items as $lc_item}
    <li class="list-compact-item">
        <a href={$lc_item.url_alias|ezurl}>{$lc_item.name|wash}</a>
        <time datetime="{$lc_item.object.published|datetime( 'custom', '%Y-%m-%d' )}">{$lc_item.object.published|l10n( 'shortdate' )}</time>
    </li>
{/foreach}
</ul>
{/if}

$block.values.items holds the content nodes of the block's collection, manual or dynamic.

3. Clear the caches

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

4. Choose it in the editor

Select a List block, Design tab, View type: list_compact is offered. Choosing it hides the options that belong to the other view types (columns, item view type).

The Design tab with View type list_compact
The Design tab with View type list_compact

Note: before explayouts_ui_api 1.3.29, changing only the view type to one like this, which leaves no item view type to choose, did not save the block; the change was stored together with the next change of another field (on the test copy a key typed and deleted in CSS class). From 1.3.29 the change is saved at once. Check the block header: it shows the saved view type in capitals, here LIST_COMPACT.

The block now shows LIST_COMPACT in its header and the items as a list
The block now shows LIST_COMPACT in its header and the items as a list

5. The result

After Publish layout the prefooter of the article pages shows the compact list:

The Most popular articles band as a plain list of four links with dates
The Most popular articles band as a plain list of four links with dates

Style .list-compact in your design's stylesheet (Styling your blocks).

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