Templates

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

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"}
      <h1>Templates</h1> <!-- the default Entry Title Field -->

      {my_first_bloq_field} <!-- the organism tag pair (aka your channel field) -->

          {content_block} <!-- the molecule tag pair (aka your block definition) -->
      
              <h2>{heading}</h2> <!-- an atom (aka individual block fields) -->
      
              {body_content} <!-- a second atom -->

          {/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: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.