CMS Development

mIIwaukee
Contributor | Diamond Partner
Contributor | Diamond Partner

Using post_formatter with an IMPORTED macro

SOLVE

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

 

0 Upvotes
1 Accepted solution
BenSBM
Solution
Contributor | Elite Partner
Contributor | Elite Partner

Using post_formatter with an IMPORTED macro

SOLVE

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" %}

View solution in original post

3 Replies 3
BenSBM
Solution
Contributor | Elite Partner
Contributor | Elite Partner

Using post_formatter with an IMPORTED macro

SOLVE

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" %}
mIIwaukee
Contributor | Diamond Partner
Contributor | Diamond Partner

Using post_formatter with an IMPORTED macro

SOLVE

Thanks @BenSBM for sharing your insightful comment!

0 Upvotes
sharonlicari
Community Manager
Community Manager

Using post_formatter with an IMPORTED macro

SOLVE

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 !


0 Upvotes