Examples

Creating a tabbed content group

Creating a tabbed content group in Bloqs is pretty easy when using nested bloqs. You can put as many bloqs or components inside of a tab. In this example there is a single component in each tab.

The template markup is where the magic happens. Since Bloqs lets you repeat the same tag pair more than once in the page, you'll create two different loops. The first loop is to render all of your tabs, either in a list, or in this example a series of buttons. And the second loop will render the actual tab panel itself, which will render the contents, or children of each tab, through the {bloqs:children} variable.

{block_tab}
    {if bloqs:is:first_child}
        <div role="tablist">
    {/if}

        <button
            role="tab"
            aria-controls="{tab_id}"
            tabindex="0"
            aria-selected="{if bloqs:is:first_child}true{if:else}false{/if}"
            data-text="{tab_label:attr_safe}"
        >
            {tab_label}
        </button>

    {if bloqs:is:last_child}
        </div>
    {/if}
{/block_tab}

{block_tab}
    {if bloqs:is:first_child}
        <div class="tab-group__panel-container">
    {/if}

        <div
            id="{tab_id}"
            role="tabpanel"
            aria-expanded="{if bloqs:is:first_child}true{if:else}false{/if}"
        >
            {bloqs:children}
        </div>

    {if bloqs:is:last_child}
        </div>
    {/if}
{/block_tab}

Displaying Assets fields in Bloqs

{bloqs_field}
    {asset_field}
        {!-- Looping over multiple files in an Assets field --}
        {asset_field:file}
            <img src="{url}" />
        {/asset_field:file}
        
        {!-- Displaying a single file in an Assets field --}
        {asset_field}
            <img src="{file:url}" />
        {/asset_field}
    {/asset_field}
{/bloqs_field}

Last updated