Using a specific blog tag in a custom module

Hi All,

I am building a custom module in HubSpot that will have a button that will open a page that displays all of the blog posts that have a specific tag. I have the module built and used the “Tag” field. the user should then be able to pick their desired tag from the drop down but it is not working properly. I have this piece of code here:

<a style=“color: white” href=“{{ blog_tag_url(“default”, “website”) }}”>Learn More</a>

I was thinking that I could just drop the field value from the Tag field into the “website” section of the code but its giving me a 404 page error. The compiler is giving this error:

Warning:20:0Blog object could not be found

Here is the entire module code here:

<div class=“MM-Corr-Blog-contaner”>
<div class=“MM-Corr-Image”>
{% if module.left_image.src %}
{% set sizeAttrs = ‘width=“{{ module.left_image.width }}” height=“{{ module.left_image.height }}”’ %}
{% if module.left_image.size_type == ‘auto’ %}
{% set sizeAttrs = ‘width=“{{ module.left_image.width }}” height=“{{ module.left_image.height }}” style=“max-width: 100%; height: auto;”’ %}
{% elif module.left_image.size_type == ‘auto_custom_max’ %}
{% set sizeAttrs = ‘width=“{{ module.left_image.max_width }}” height=“{{ module.left_image.max_height }}” style=“max-width: 100%; height: auto;”’ %}
{% endif %}
{% set loadingAttr = module.left_image.loading != ‘disabled’ ? ‘loading=“{{ module.left_image.loading }}”’ : ‘’ %}
<img src=“{{ module.left_image.src }}” alt=“{{ module.left_image.alt }}” {{ loadingAttr }} {{ sizeAttrs }}>
{% endif %}
</div>
<div class=“MM-Corr-Text-container”>
<div class=“MM-Corr-Text”>
{% inline_rich_text field=“body_text” value=“{{ module.body_text }}” %}
</div>
</div>
<div class=“MM-Corr-Posts”>

<a style=“color: white” href=“{{ blog_tag_url(“default”, “{{ module.blog_post_tag }}”) }}”>Learn More</a>

</div>
</div>

You can see a page that has the module on it here: https://jonestheagency-com.sandbox.hs-sites.com/marcome_mode_test in the section with the Octapus.

This should be simple but I am perplexed. Any help would be appreciated.

Thanks

Scott

Hi @SlimSr2003,

since Hubl is serverside rendering you can’t pass data from the frontend(e.g. user selection) directly to it.

If you would like to provide your marketers/page editors the ability to select a certain tag and therefore build buttons to the tag-pages. That’s definetely possible.

Double curly-braces don’t work inside other curly-braces. So this code:

<a style="color: white" href="{{ blog_tag_url("default", "{{ module.blog_post_tag }}") }}">Learn More</a>

should be like this:

<a style="color: white" href="{{ blog_tag_url("default", module.blog_post_tag ) }}">Learn More</a>

Hope that helps.

best,

Anton

Hi Anton,

Thanks for the reply. I think I understand what you are getting at. But I have a couple of questions.

What did you mean by this comment: If you would like to provide your marketers/page editors the ability to select a certain tag and therefore build buttons to the tag-pages. That’s definetely possible.

That sound like what I am trying to do. I would like them to select from a drop down in the module (see “Module Image 1” in the attachment). Then the button in the module would send them to a page that as all of the blog posts with that tag. Similiar to the attached image “blog tag page 1” attached.

If you have ideas as to how to accomplish this I would appreciate your help.

Also, after messing with it a bit more today I have added a piece of text with the code below to show what the drop down is returning. See Module Example 1 attached.

After messing with it and removing the {} brackets and having the code like this:

<a style=“color: white” href=“{{ blog_tag_url(“default”, “module.blog_post_tag”) }}”>Learn More</a>

I am getting this error: 1. Warning:20:0Blog object could not be found

Its not working right now but now its not producing a 404 page, just reloading the page.

I appreciate your time and thoughts on this.

Scott

Hi @SlimSr2003,

thank you for clearification and the providing screens.

How is your tag function set up? Have you selected “Slug” as option?

Also - you’re getting the notification since you haven’t selected a tag as default. You can but don’t have to select one as a default.

Also - quick tipp:

Use this code

<a style="color:white" href="{{ blog_tag_url("default", module.blog_post_tag) }}">Learn More</a>

(you don’t need quotation marks around the module function)

best,

Anton

Hi Anton,

You were right on the money. I didn’t have Slug selected as the type of tag. Also your recomendation about removing the quotation marks was correct as well. Also, I didn’t have any posts that were tagged with the one I was selecting and that was also causing an issue. This has fixed all my issues thank you so much for your time and help!.

Scott