# Need some help in using macros

**URL:** <https://zola.discourse.group/t/need-some-help-in-using-macros/65>\
**Category:** Support\
**Created:** [February 26, 2019, 7:47am UTC](https://zola.discourse.group/t/need-some-help-in-using-macros/65 "2019-02-26T07:47:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikevin8me](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@ikevin8me](https://zola.discourse.group/u/ikevin8me)\
**Post date:** [February 26, 2019, 7:47am UTC](https://zola.discourse.group/t/need-some-help-in-using-macros/65/1 "2019-02-26T07:47:55Z")

</div>

I’m using Zola with Tera and I have repeating code within the HTML. I’m trying to put it into macros but can’t figure it out. Please help! 🙂

The code is:

```
{% set section = get_section(path="Section_A/_index.md") %}
    {% set sectionsPagesCount = section.pages | length %}
    {% set_global sectionsPhotosCount = 0 %}
    {% for page in section.pages %}
      {% set pagePhotosCount = page.assets | length %}
      {% set_global sectionsPhotosCount = sectionsPhotosCount + pagePhotosCount %}
    {% endfor %}

    <div class="col-lg-3 col-md-6 mb-lg-0 mb-4">
      <div class="card card-cascade narrower card-ecommerce">
        {% include "section_image.html" %}
        {% include "section_info.html" %}
      </div>
    </div>

    {% set section = get_section(path="Section_B/_index.md") %}
    {% set sectionsPagesCount = section.pages | length %}
    {% set_global sectionsPhotosCount = 0 %}
    {% for page in section.pages %}
    {% set pagePhotosCount = page.assets | length %}
    {% set_global sectionsPhotosCount = sectionsPhotosCount + pagePhotosCount %}
    {% endfor %}

    <div class="col-lg-3 col-md-6 mb-lg-0 mb-4">
      <div class="card card-cascade wider card-ecommerce">
        {% include "section_info.html" %}
        {% include "section_image.html" %}
      </div>
    </div>

    {% set section = get_section(path="Section_B/_index.md") %}
    {% set sectionsPagesCount = section.pages | length %}
    {% set_global sectionsPhotosCount = 0 %}
    {% for page in section.pages %}
    {% set pagePhotosCount = page.assets | length %}
    {% set_global sectionsPhotosCount = sectionsPhotosCount + pagePhotosCount %}
    {% endfor %}

    <div class="col-lg-3 col-md-6 mb-lg-0 mb-4">
      <div class="card card-cascade narrower card-ecommerce">
        {% include "section_image.html" %}
        {% include "section_info.html" %}
      </div>
    </div>

```

… and so on.

As you can see, only the first line line “set section = …” is unique. The rest of the lines until the {% endfor %} are the same.

How do I use macros?

(I also tried to use include, but it didn’t work.)

Thanks!

---

<div class="post-metadata">

**Author:** ![paulcmal](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/paulcmal/32/32_2.png) [@paulcmal](https://zola.discourse.group/u/paulcmal)\
**Post date:** [March 6, 2019, 4:33pm UTC](https://zola.discourse.group/t/need-some-help-in-using-macros/65/2 "2019-03-06T16:33:02Z")

</div>

Hi, have you tried reading [Tera’s docs about macros](https://tera.netlify.com/docs/templates/#macros)? Tera is the templating engine used by Zola so in case you have troubles with Zola templates you should go take a look in Zola’s docs.

If the examples in the docs are not clear feel free to ask more questions 🙂  
Good luck working on your macros!
