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:
1
{exp:channel:entries channel="page"}
2
{my_bloq_field} <!-- This is the Bloqs custom field -->
3
4
{content_bloq} <!-- This is a bloq tag pair -->
5
{heading} <!-- This is an atom inside of a bloq -->
6
{bloqs:count} <!-- This is one of the context variables below -->
7
{/content_bloq}
8
9
{featured_article_bloq} <!-- Another bloq tag pair -->
10
{bloqs:count} <!-- This will also work -->
11
{/featured_article_bloq}
12
13
{bloqs:count} <!-- This will not work here -->
14
15
{/my_bloq_field}
16
{/exp:channel:entries}
Copied!
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: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

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.
1
{exp:channel:entries channel="page"}
2
{my_bloq_field bloq_var_some_key="some-value"}
3
{content_bloq}
4
{heading}
5
{body_content}
6
{if bloq_var_some_key == "some-value"}
7
Do something
8
{/if}
9
{/content_bloq}
10
{/my_bloq_field}
11
{/exp:channel:entries}
Copied!

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.
1
{exp:channel:entries channel="page"}
2
{my_bloq_field}
3
{section_wrapper_bloq}
4
{bloqs:set name="foo" value="bar"}
5
{/section_wrapper_bloq}
6
7
{content_bloq}
8
{bloqs:get:foo}
9
{/content_bloq}
10
{/my_bloq_field}
11
{/exp:channel:entries}
Copied!

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.
1
{exp:channel:entries channel="page"}
2
{my_bloq_field}
3
{section_wrapper_bloq}
4
{bloqs:get:scoped:foo}
5
{/section_wrapper_bloq}
6
7
{content_bloq}
8
{bloqs:set name="foo" value="bar" scope="{bloqs:parent:id}"}
9
{/content_bloq}
10
{/my_bloq_field}
11
{/exp:channel:entries}
Copied!
If you're not using the nesting feature, and rendering bloqs sequentially, you can send a variable value to a previous bloq.
1
{exp:channel:entries channel="page"}
2
{my_bloq_field}
3
{section_wrapper_bloq}
4
{bloqs:get:scoped:foo}
5
{/section_wrapper_bloq}
6
7
{content_bloq}
8
{bloqs:set name="foo" value="bar" scope="{bloqs:previous:id}"}
9
{/content_bloq}
10
{/my_bloq_field}
11
{/exp:channel:entries}
Copied!
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).
1
{exp:channel:entries channel="page"}
2
{my_bloq_field}
3
{section_wrapper_bloq}
4
{bloqs:get:scoped:foo}
5
{/section_wrapper_bloq}
6
7
{row_wrapper_bloq}
8
{bloqs:get:scoped:foo}
9
{/row_wrapper_bloq}
10
11
{content_bloq}
12
{bloqs:set name="foo" value="bar" scope="{bloqs:parent:ids}"}
13
{/content_bloq}
14
{/my_bloq_field}
15
{/exp:channel:entries}
Copied!
Last modified 11d ago