We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
Apr 24, 2020 12:13 PM - edited Apr 24, 2020 12:16 PM
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
Solved! Go to Solution.
Apr 28, 2020 1:58 PM
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" %}
Apr 28, 2020 1:58 PM
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" %}
Apr 28, 2020 2:46 PM
Thanks @BenSBM for sharing your insightful comment!
Apr 28, 2020 7:16 AM
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
![]() | ¿Sabías que la Comunidad está disponible en Español? ¡Participa hoy en conversaciones en el idioma de tu preferencia,cambiando el idioma en tus configuraciones! Did you know that the Community is available in other languages? Join regional conversations by changing your language settings ! |