How to Add Retina Images to HubSpot Email and Page Templates

HubSpot CMS handles responsive images by default by creating different image sizes for different screen widths (using srcset). But with retina display images, you want to load higher resolution images and scale them down to 100%. Thankfully you can add ?noresize to the end of your image source to disable this dynamic resizing.

In the example below I added a linked image tag to an email template. I want a content author to update the values but have more control over the output of the code. So I added two important attributes to the tag.

  • export_to_template_context=True This tells it to store the data and make it accessible but not to actually render the code for it on the page
  • no_wrapper=True This tells it not to add any div wrapper around content if displayed on the page.

Next I give it a unique name of “hero_image” I then can use that name to reference the values anywhere I want in my template using this HubL code snippet formula {{ widget_data.your-unique-name.value }}

Below is an example of how I used this to create an email hero image that is optimized for retina displays. The author adds an image 1200px wide but it is scaled down to 600px wide in the template. Keep in mind, you probably don’t want to use retina images everywhere to prevent slow page loading. Use it in areas that will have a lot of

{% linked_image "hero_image" label='Hero Image', link="", open_in_new_tab=True, alt='hero image alt', src='//', width='600', export_to_template_context=True, no_wrapper=True %}
{{ widget_data.hero_image }}<br>
{{ }}<br>
{{ widget_data.hero_image.src }}<br>
{{ widget_data.hero_image.alt }}<br>
{# email templates automatically add target="_blank" regardless of setting #}
{{ widget_data.hero_image.open_in_new_tab }}<br>
{{ widget_data.hero_image.width }}
{% if %}<a href="{{ }}" {% if widget_data.hero_image.open_in_new_tab %}target="_blank"{% endif %}>{% endif %}
<img src="{{ widget_data.hero_image.src }}?noresize" width="{{widget_data.hero_image.width}}" alt="{{widget_data.hero_image.alt}}" />
{% if %}</a>{% endif %}

What the HubL code will output on the page

{src=//, open_in_new_tab=true, no_wrapper=true, link=, alt=hero image alt, width=600, parent_widget_container=null, label=Hero Image, export_to_template_context=true, content_editable_values=[alt, src, link, open_in_new_tab, width, height]}<br><br>
hero image alt<br>

<a href="" target="_blank" data-hs-link-id="0">
<img src="//" width="600" alt="hero image alt">


Written by: Jake Lett
I share digital marketing tips and HubSpot tutorials to help marketers and business owners grow their business.


Related posts

Tags: , ,

Want to Get Email Updates of New Articles?

Join My Email Newsletter