Using post_formatter with an IMPORTED macro

Hi,

Running into issues with macros and related posts (related_blog_posts).

Macros are an external file that’s imported like this:

{% import ‘/_blog-macros.html’ as blog_macros %}

A macro I want to use is

{% macro format_post(blog_post) %} {% endmacro %}

Works everywhere:

{{ blog_macros.format_post(the_post) }}

Exception: related blog posts wont accept the imported syntax…

{% related_blog_posts limit=3, post_formatter=‘blog_macros.format_post’ %}

Errors as

“Macro function does not exist”

Am I missing something?

thanks!

mark

Hey @mIIwaukee

Thanks for reaching out! I want to tag in some subject matter experts to get their insight on this situation.

Hey, @JanetArmstrong @ajchapman20 @narmstrong do you have any suggestions for @mIIwaukee ?

Thanks,

Sharon

Hi @mIIwaukee

This looks to me like a possible oversight from HubSpot where it won’t let you use an imported macro. A workaround does exist, however being a workaround it’s not 100% ideal.

The idea is to add a macro that acts as a wrapper, and passes the post info to the import macro. It doesn’t really help as far as keeping all macros contained within one file, but does help in the sense that it at least keeps the main post formatter macro in a separate file.

{% import '/path/to/macros.html' as macros %}
{% macro inline_formatter(post) %}
 {{ macros.custom_post_formatter(post) }}
{% endmacro %}

{% related_blog_posts limit=3, post_formatter="inline_formatter" %}

Thanks @BenSBM for sharing your insightful comment!