Template Tags

At the most basic level, templating with Bloqs is nothing more than the standard EE tag pair/tag process. But tag pairs in Bloqs go a bit deeper than what you might normally expect to encounter in ExpressionEngine. Let's take a look at an example so you can see how the logic plays out.

Example

Suppose we have a very simple "Page" Channel in ExpressionEngine which contains 1 Bloq field.

Our setup might look something like this:

Channel Short Name: page

Channel Fields:

  • Field Type: Bloqs

  • Field Name: My First Bloq Field

  • Field Short Name: my_first_bloq_field

    • Selected Block Types/Definition: Content Block

Bloq Definitions:

  • Block Type/Definition: Content Block

  • Block Short Name: content_block

  • Block Atom Definitions:

    • Atom Name: Heading

    • Atom Short Name: heading

    • Atom Name: Body Content

    • Atom Short Name: body_content

Templates

Given our base definitions, to output the content in a Page Channel Entry, your template code would look similar to the following:

{exp:channel:entries channel="page"}
{my_first_bloq_field}
{content_block}
{heading}
{body_content}
{/content_block}
{/my_first_bloq_field}
{/exp:channel:entries}

As of version 4.2.2, you can pass variables into a block field, or override an existing block var:

{exp:channel:entries channel="page"}
{my_first_bloq_field block_var_some_key="some-value"}
{content_block}
{heading}
{body_content}
{if block_var_some_key == "some-value"}
Do something
{/if}
{/content_block}
{/my_first_bloq_field}
{/exp:channel:entries}

Context Variables

There are also some special variables that may be used in your templates.

{blocks:all_vars} List out all of the variables below, and their values in your template for debugging purposes.

{blocks:id} The unique ID of the block being displayed.

{blocks:count} The count of the current block being displayed. The first block will have a value of "1", the next "2", etc.

{blocks:index} The zero-based index of the block being displayed. The first block will have a value of "0", the next "1", etc.

{blocks:total_blocks} The total number of blocks to display.

{blocks:total_rows} The same as {blocks:total_blocks} but for people who feel more comfortable with Grid terminology

{blocks:count:of:type} The count of the current block being displayed for this particular type. The first block of this type will have a value of "1", the next "2", etc.

{blocks:index:of:type} The zero-based index of the block being displayed for this particular type. The first block of this type will have a value of "0", the next "1", etc.

{blocks:total_blocks:of:type} The total number of blocks of the current type to display.

{blocks:total_rows:of:type} The same as {blocks:total_blocks:of:type} but for people who feel more comfortable with Grid terminology

{blocks:previous:shortname} The shortname of the block that precedes the current block, or "" if this is the first block.

{blocks:next:shortname} The shortname of the block that follows the current block, or "" if this is the last block.

:total_blocks {your_field_name:total_blocks} returns the number of total blocks that the field contains. This may be useful for conditionally including the field. E.g., {if "{your_field_name:total_blocks}" > "0"}.

:total_blocks - with "type" parameter (optional) {your_field_name:total_blocks type="shortname"} will return the number of blocks defined for a particular type, as specified by the block type shortname.