# Unexpected macro behaviour in shortcodes vs templates

**URL:** <https://zola.discourse.group/t/unexpected-macro-behaviour-in-shortcodes-vs-templates/2543>\
**Category:** Support\
**Created:** [March 20, 2025, 7:34pm UTC](https://zola.discourse.group/t/unexpected-macro-behaviour-in-shortcodes-vs-templates/2543 "2025-03-20T19:34:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tzinm](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@tzinm](https://zola.discourse.group/u/tzinm)\
**Post date:** [March 20, 2025, 7:34pm UTC](https://zola.discourse.group/t/unexpected-macro-behaviour-in-shortcodes-vs-templates/2543/1 "2025-03-20T19:34:20Z")

</div>

When using macros within templates, I’ve noticed a difference in behaviour compared to when they are used inside a shortcode.

Consider the following macro structure:

```auto
├── templates/
│ ├── macros
│ │ ├── first_macro.html
│ │ └── second_macro.html

```

In `second_macro.html`, there is a reference to `first_macro.html` without an explicit import:

```auto
{%- set first_macro = first_macro::macro_action() -%}

```

Both macros are imported in `base.html`, and when used within templates, everything works fine. However, when calling `second_macro.html` from a shortcode, an error occurs stating that `first_macro.html` cannot be found despite both macros being imported at the beginning of the shortcode.

```auto
Error: Reason: Failed to render 'shortcodes/books.md': error while rendering macro `first_macro::macro_action`
Error: Reason: Macro namespace `first_macro` was not found in template `macros/second_macro.html`. Have you maybe forgotten to import it, or misspelled it?

```

If I explicitly import `first_macro.html` inside `second_macro.html`, the error disappears.

Is this the expected behavior? Or could this be a limitation or bug in Zola/Tera?

---

<div class="post-metadata">

**Author:** ![zolappom](https://avatars.discourse-cdn.com/v4/letter/z/48db29/32.png) [@zolappom](https://zola.discourse.group/u/zolappom)\
**Post date:** [March 27, 2025, 10:14am UTC](https://zola.discourse.group/t/unexpected-macro-behaviour-in-shortcodes-vs-templates/2543/2 "2025-03-27T10:14:15Z")

</div>

I don’t have a precise answer to your question, but I’d suggest putting both macros in the same html file 🙂
