Context Variables

All Bloqs fields have context variables available. Regardless of what your field or atom names are, the following special variables can be used in your Bloqs field tag pairs. These variables are only available inside of a bloq tag pair (the same level as an atom). For example:

{exp:channel:entries channel="page"}
    {my_bloq_field} <!-- This is the Bloqs custom field --> 
        
        {content_bloq} <!-- This is a bloq tag pair --> 
            {heading} <!-- This is an atom inside of a bloq -->
            {bloqs:count} <!-- This is one of the context variables below -->
        {/content_bloq}
        
        {featured_article_bloq} <!-- Another bloq tag pair -->
            {bloqs:count} <!-- This will also work -->
        {/featured_article_bloq}
        
        {bloqs:count} <!-- This will not work here -->
        
    {/my_bloq_field}
{/exp:channel:entries}

Please note that as of version 4.4.0, there was a universal change in the Bloqs UI, documenation, and variables of all references of "block" and "blocks" to "bloq" and "bloqs". If upgrading from a version prior to 4.4.0, your old{blocks:total_blocks} variables will still work. For every variable listed below, there is an {blocks:*} alias for it. If you are using a version prior to 4.4.0, then you must use the old variable prefixes, e.g. {blocks:*}

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

{bloqs:id} The unique ID of the current bloq being displayed.

{bloqs:shortname} The short name of the current bloq being displayed.

{bloqs:template:shortname} If the current bloq is a template wrapper, this will display the template's short name from it's definition data ({bloqs:shortname} will always be __template_wrapper , this variable helps provide a unique name to reference)

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

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

{bloqs:total_bloqs} The total number of bloqs to display.

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

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

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

{bloqs:total_bloqs:of:type} The total number of bloqs of the current type to display.

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

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

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

{bloqs:switch="one|two|three"} Works the same way as the {switch=""} variable in a channel:entries tag, but with bloqs. Note that this takes into account all bloqs of the same type within a specific field. If using nested bloqs or components the context/depth of a bloq will not reset the switch value.

The following context variables are useful when using a nested bloqs field.

{bloqs:is:first_child} Boolean - If this bloq is the first child of a parent bloq.

{bloqs:is:last_child} Boolean - If this bloq is the last child of a parent bloq.

{bloqs:root:id} If a bloq is a child of another bloq, this will be the value of the nearest parent bloq at the root level.

{bloqs:is:root} Boolean - If this bloq is at the root level (it doesn't have any parents).

{bloqs:parent:id} The id of the parent bloq

{bloqs:parent:ids} Similar to {bloqs:parent:id}, but when the bloq is a child of another bloq, this will report all of it's parent bloq IDs up to the root level. For example: '123|124|125'

{bloqs:parent:shortname} The short_name of the parent bloq

{bloqs:children} This will render all child bloqs of a current bloq. You do not need to do anything special when using this tag. Bloqs will automatically grab the content of other {my_bloq}{/my_bloq} tag pairs and insert them into their proper location.

{bloqs:child:my_bloq} New in Bloqs 5.0 - Instead of using the :children tag, you can selectively choose which children of a bloq get rendered, and where in the parent bloq tag pair they get rendered. Note, however, that if your template markup does not include a child tag of a particular bloq, but the bloq exists in the Entry data, it will not render on the front-end. These child tags and the {bloqs:children} tag are mutually exclusive.

{bloqs:children:total_bloqs} If a bloq has children, display how many children it has.

{bloqs:children:total_rows} The same as {bloqs:children:total_bloqs} but for people who feel more comfortable with Grid terminology

{bloqs:siblings:total_bloqs} How many siblings, at the same nesting level, the current bloq has.

{bloqs:siblings:total_rows} The same as {bloqs:siblings:total_bloqs} but for people who feel more comfortable with Grid terminology

{bloqs:depth} New in Bloqs 5.0 -Use this variable to output an integer value of how deep the current bloq is inside of a nested bloq structure.

{bloqs:count:at:depth} New in Bloqs 5.0 -Just like the {count} variable, this will output an integer value of the total bloqs at the same depth as the current bloq. If you have a single root level bloq with 3 children, the first child will have a {bloqs:count:at:depth} value of 1, and the last will have a value of 3, but the {bloqs:count} value of the 3rd child will be 4, since it is the 4th total bloq displayed.

Variable Modifiers

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

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

Bloq Variables

Bloq variables are an advanced feature. If you add a parameter to your Bloqs field tag pair with the prefix bloq_var_, then the value of that parameter will be made available within your bloq tag pairs. This parameter can override, or workin tandem with the bloq_var's when nesting bloqs.

As of version 4.9, {bloq_var_[name]} and {bloqs:get:[name]} are interchangable.

{exp:channel:entries channel="page"}
    {my_bloq_field bloq_var_some_key="some-value"} 
        {content_bloq}  
            {heading}
            {body_content}
            {if bloq_var_some_key == "some-value"}
                Do something
            {/if}
        {/content_bloq}
    {/my_bloq_field}
{/exp:channel:entries}

Bloq Variable Setters & Getters

As of version 4.9, Bloqs now has variable setters and getters, which are very similar to ExpressionEngine's Layout Variables. So similar infact that it uses the same parsing code. For example you can set a variable with a value and later reference the variable in a child bloq, or the next bloq in the sequence if not using the nesting feature.

{exp:channel:entries channel="page"}
    {my_bloq_field} 
        {section_wrapper_bloq}
            {bloqs:set name="foo" value="bar"}
        {/section_wrapper_bloq}
        
        {content_bloq}  
            {bloqs:get:foo}
        {/content_bloq}
    {/my_bloq_field}
{/exp:channel:entries}

Bloq Variable Scoping

You can also set a variable in a child bloq, and pass a value back up to it's immediate parent bloq. Scoping currently only supports bloq IDs as values. Text based named scoping is not currently supported.

{exp:channel:entries channel="page"}
    {my_bloq_field} 
        {section_wrapper_bloq}
            {bloqs:get:scoped:foo}
        {/section_wrapper_bloq}
        
        {content_bloq}  
            {bloqs:set name="foo" value="bar" scope="{bloqs:parent:id}"}
        {/content_bloq}
    {/my_bloq_field}
{/exp:channel:entries}

If you're not using the nesting feature, and rendering bloqs sequentially, you can send a variable value to a previous bloq.

{exp:channel:entries channel="page"}
    {my_bloq_field} 
        {section_wrapper_bloq}
            {bloqs:get:scoped:foo}
        {/section_wrapper_bloq}
        
        {content_bloq}  
            {bloqs:set name="foo" value="bar" scope="{bloqs:previous:id}"}
        {/content_bloq}
    {/my_bloq_field}
{/exp:channel:entries}

Finally, you can also set a variable and reference it from all of it's parent bloqs (note the variable modifier is :ids, not :id).

{exp:channel:entries channel="page"}
    {my_bloq_field} 
        {section_wrapper_bloq}
            {bloqs:get:scoped:foo}
        {/section_wrapper_bloq}
        
        {row_wrapper_bloq}
            {bloqs:get:scoped:foo}
        {/row_wrapper_bloq}
        
        {content_bloq}  
            {bloqs:set name="foo" value="bar" scope="{bloqs:parent:ids}"}
        {/content_bloq}
    {/my_bloq_field}
{/exp:channel:entries}

Last updated