Trouble Getting Links on Logo Grid Module

Hello HubSpot Developer Community, hoping for a learning experience for this newbie…

The default module Logo Grid (theme Brightlane) doesn’t let you add URL links to the logos. I’m trying to add in the code to do this and I can’t get it to work.

Here’s the original code:

{% set logos = module.group_logos %}
{% set grid_settings = module.styles.group_logo_grid %}
{% set logo_styles = module.styles.group_logo %}
{% set grid_basis_spacing = grid_settings.grid_gap - (grid_settings.grid_gap / grid_settings.column_count) %}
{% set column_count_percentage = ((1 / grid_settings.column_count) * 100) ~ “%” %}

{% macro add_style_if_value(style, field, unit = “”) %}
{% set field_with_unit = field ~ unit %}
{{ style }}: {{ field_with_unit }};
{% endmacro %}

{% require_css %}

<style>

@Layer module {
{% scope_css %}
.hs-logo-grid {
gap: {{ grid_settings.grid_gap ~ “px” }};
}
.hs-logo-grid__logo-wrapper {
flex: 0 1 calc({{ column_count_percentage }} - {{ grid_basis_spacing ~ “px” }});
max-width: calc({{ column_count_percentage }} - {{ grid_basis_spacing ~ “px” }});
{{ add_style_if_value(“aspect-ratio”, logo_styles.group_background.aspect_ratio) }}
{{ add_style_if_value(“background-color”, logo_styles.group_background.background_color.css ) }}
{{ logo_styles.group_spacing.padding.css }}
}
.hs-logo-grid__logo {
max-height: {{ logo_styles.max_logo_height ~ “px” }};
}
{% end_scope_css %}
}
</style>

{% end_require_css %}

{% macro build_image(image) %}
{% if image.src %}
{% set sizeAttrs = ‘width=“{{ image.width }}” height=“{{ image.height }}”’ %}
{% set loadingAttr = image.loading != ‘disabled’ ? ‘loading=“{{ image.loading }}”’ : ‘’ %}
<img class=“hs-logo-grid__logo” src=“{{ image.src }}” alt=“{{ image.alt }}” {{ loadingAttr }} {{ sizeAttrs }}>
{% endif %}
{% endmacro %}

{% macro build_logo_grid() %}
{% for item in logos %}
<div class=“hs-logo-grid__logo-wrapper”>
{{ build_image(item.logo) }}
</div>

{% endfor %}
{% endmacro %}

<div class=“hs-logo-grid”>
{{ build_logo_grid() }}
</div>

---

I added in the new Link Field variable already ‘link_url’. With options to link to External/Content/File/Blog/etc.

When I tried adding in a href into the build_image it didn’t work as I expected.

Can someone help me get my new field referenced within the HTML so it actually does something?

Hello @babs!
You will need to wrap the elements you want to make clickable in an <a> tag.

You could add it inside the <div class=“hs-logo-grid”> or just turn that <div> into an <a> tag but preserving the class to avoid issues with styles.

You might still need to add certain CSS as <a> tags might have already predefined styles in your theme.

Then, make sure the <a> tag includes your field variable, something like this:

<a href="{{module.link.url.href}}" class="hs-logo-grid">
 {{ build_logo_grid() }}
</a>

Hope this helps!

Thank you so much for the quick response. It sounds so easy, but I must be entering the variable incorrectly, because when I use the module, the URL just links back to the page the module is on. It’s not pulling the URL I enter. I feel like I’ve tried every variation to get it to link. Anything else you can advise on to get me there?

I realize I made a typo on the code I sent you before, I was copying & pasting something from one of my modules and didn’t update the variable name.

The code below should work based on your variables:

<a href="{{item.link_url.url.href}}" class="hs-logo-grid__logo-wrapper">
{{ build_image(item.logo) }}
</a>

Let me know if that works!

Thanks!! That did the trick, just needed to revise some CSS and all is working. Appreciate it!