Helper: blocks/group

« All helpers

Renders the specified list of content blocks one after another, while also fetching them in a single database query, instead of incurring multiple calls to the database for multiple blocks. Use this in layout templates like this:

{! blocks/group/block-one/block-two/block-three !}

Or on several lines like this:

{! blocks/group
   ?id[]=block-one
   &id[]=block-two
   &id[]=block-three !}

Or you can specify a wildcard and it will fetch all blocks that match, sorted by ID ascending:

{! blocks/group?wildcard=page-* !}

This can be combined with the page ID and the rows parameter to create a series of editable divs on a page, like this:

{! blocks/group?wildcard=[id]-*&rows=on !}

The above tag would fetch any blocks beginning with the current page ID followed by a hyphen - and anything else (numbers, text), and wrap them in divs like this:

<div class="block-outer" id="block-outer-pageid-1">
    <div class="e-row">
        <div class="block e-col-100" id="block-pageid-1">
            <h2>Block title</h2>
            <p>Block contents...</p>
        </div>
    </div>
</div>
<div class="block-outer" id="block-outer-pageid-2">
    <div class="e-row">
        <div class="block e-col-100" id="block-pageid-2">
        <h2>Block title</h2>
        <p>Block contents...</p>
        </div>
    </div>
</div>

You can also set a level parameter to specify which heading level to use for the block titles:

{! blocks/group
   ?id[]=block-one
   &id[]=block-two
   &level=h2 !}

Additionally, you can set a divs parameter to specify that each block should be wrapped in a <div class="block" id="block-ID"></div> tag, where the id attribute's value is the block ID prefixed with block-:

{! blocks/group
   ?id[]=sidebar-promo
   &id[]=sidebar-support
   &divs=on !}

This will output:

<div class="block" id="block-sidebar-promo">
    <h2>Block title</h2>
    <p>Block contents...</p>
</div>
<div class="block" id="block-sidebar-support">
    <h2>Block title</h2>
    <p>Block contents...</p>
</div>

In this way, blocks can easily be styled collectively or individually, making them a powerful way to build site content.

You can also specify a units parameter, which specifies the width of each div as an e-col-%d class, for example:

{! blocks/group
   ?id[]=sidebar-promo
   &id[]=sidebar-support
   &units=75,25 !}

This will output:

<div class="block e-col-75" id="block-sidebar-promo">
    <h2>Block title</h2>
    <p>Block contents...</p>
</div>
<div class="block e-col-25" id="block-sidebar-support">
    <h2>Block title</h2>
    <p>Block contents...</p>
</div>

The use of units will automatically include the admin/util/minimal-grid helper, which provides a very minimal responsive grid system for page content.