# Template Tags

{% hint style="info" %}
Bloqs supports the Template Generator feature of ExpressionEngine 7.5. It'll output all the necessary tags for your Bloqs field. You will of course need to add your html around the tags, but the generated template will give you a jump start.
{% endhint %}

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:

```html
{exp:channel:entries channel="page"}
    {my_bloqs_field}
        <!-- Note that any html here will not render. Only content within
        the tag pairs below will render. -->
        <div class="container">For example, this will not be output</div>
        
        {content_bloq}
            <div class="container">
                <h2>{heading}</h2>
                {body_content}
            
                <!-- If using nested bloqs, you'll want to add the {bloqs:children}
                tag within each bloq that might have one or more children -->
                <div class="children-container">
                    {bloqs:children}
                </div>
            </div>
        {/content_bloq}
        
        <!-- Working with file field examples -->
        {media_bloq}
            <div class="container">
                {media_bloq:file_field}
                    <img src="{url}" />
                {/media_bloq:file_field}
                
                <!-- Or -->
                
                <img src="{media_bloq:file_field:resize width='90' height='90'}" />
                
                <!-- Or -->
    
                {media_bloq:file_field:webp}
                     <img src="{url}" />
                {/media_bloq:file_field:webp}
                
                <!-- Or -->
                
                <img src="{file_field}" />
            </div>
        {/media_bloq}
        
    {/my_bloqs_field}
{/exp:channel:entries}
```

{% hint style="info" %}
Note the file fields in the above example are prefixed with the bloq name. If you have *any custom field that uses a tag pair inside of a bloq* (e.g. File, Relationship, Ansel, or Simple Grid & Tables), you will likely have to prefix the field name with the bloq name. This is simply an issue with the native EE template parser.

```html
{my_bloq}
    {my_bloq:my_ansel_field}
        <img src="{img:url}" />
    {/my_bloq:my_ansel_field}
{/my_bloq}
```

You may also want to avoid prefixing your bloqs with the same name as the bloqs field, and atom's with the same name as the parent blog's field name. Prefixing is handy in most cases, but the ExpressionEngine template parser can get confused. If you run into any template parsing issues, this should be the first thing you look into.

```html
{exp:channel:entries channel="page"}
    {bloqs_field}
        {bloqs_field_hero}
            {hero_heading}
            {hero_content}
        {/bloqs_field_hero}
    {/bloqs_field}
{/exp:channel:entries}
```

{% endhint %}

A slight more advanced example including a *Feature Component* bloq:

```html
{exp:channel:entries channel="page"}
    {my_bloqs_field}
        {content_bloq}  
            {heading}
            {body_content}
        {/content_bloq}
        
        {feature_component}
            {if bloqs:is:first_child}
                <div class="features">
            {/if}
            <div class="feature">
                <div class="feature-title {bloqs:switch='yellow|purple|green'}">
                    <img src="{feature_icon}">
                    {feature_name}
                </div>
                <a class="cover-link" href="{feature_link}"></a>

                {bloqs:children}

            </div>
            {if bloqs:is:last_child}
                </div>
            {/if}
        {/feature_component}
    {/my_bloqs_field}
{/exp:channel:entries}
```

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](/bloqs/docs/context-variables.md) next.

If you are using the bloq nesting feature, then [more template examples are available](/bloqs/docs/features/nesting.md#template-tags).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.boldminded.com/bloqs/docs/template-tags.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
