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.
Lets say we have a single bloq type defined with 2 atoms:
    Bloq Name: Content Bloq
    Bloq Short Name: {content_bloq}
    Bloq Atom Definitions:
      Atom Name: Heading
      Atom Short Name: {heading}
      Atom Name: Body Content
      Atom Short Name: {body_content}
And this bloq type is added to a Bloqs custom field assigned to the Pages channel.
    Field Type: Bloqs
    Field Name: My Bloqs Field
    Field Short Name: {my_bloqs_field}
      Selected Bloq Types: Content Bloq
Given our base definitions, to output the content in a Pages Channel Entry, your template code would look similar to the following:
1
{exp:channel:entries channel="page"}
2
{my_bloqs_field}
3
{content_bloq}
4
{heading}
5
{body_content}
6
{/content_bloq}
7
{/my_bloqs_field}
8
{/exp:channel:entries}
Copied!
A slight more advanced example including a Feature Component bloq:
1
{exp:channel:entries channel="page"}
2
{my_bloqs_field}
3
{content_bloq}
4
{heading}
5
{body_content}
6
{/content_bloq}
7
8
{feature_component}
9
{if bloqs:is:first_child}
10
<div class="features">
11
{/if}
12
<div class="feature">
13
<div class="feature-title {bloqs:switch='yellow|purple|green'}">
14
<img src="{feature_icon}">
15
{feature_name}
16
</div>
17
<a class="cover-link" href="{feature_link}"></a>
18
19
{bloqs:children}
20
21
</div>
22
{if bloqs:is:last_child}
23
</div>
24
{/if}
25
{/feature_component}
26
{/my_bloqs_field}
27
{/exp:channel:entries}
Copied!
At the bottom of a Bloqs custom field settings page will be a live basic example template based on the bloqs you've created for your project you can use to get started. Once you've created your basic field tag pairs, you may need to use Context Variables to assist in the rendering of the output. Read more about Context Variables next.
If you are using the bloq nesting feature, then more template examples are available.
Last modified 1mo ago
Copy link