Section templates, context variables and theme images.

I have a page template referencing a section template and I am trying to use the context variable to change the default image shown for this section to another image in the theme.

Normally, in the template html, I would reference a theme image with

get_asset_url("../images/theme-image.jpg")

And in the section template

img={ "src": context.image || get_asset_url("../images/another-image.jpg") }

However, in the page template the following gives a template compilation error:

{% include_dnd_partial path="../sections/custom-section.html" 
 context={image: get_asset_url("../images/theme-image.jpg") }
 %}

I’ve tried setting a variable to the asset url and assigning that to image. No error is generated but the image is ignored. E.g.

{% set my_image = get_asset_url("../images/theme-image.jpg") %}
{% include_dnd_partial path='../sections/custom-section.html'
 context={
 image: my_image
 }
%}

What is the correct way to pass an image src value via the context variable to a section template?

Hi @ChrisSequel


I haven’t tried your exact use case, but what I did is upload the default image to my theme and used an ablsolute URL. I got the URL by right clicking the image in the theme and select copy path.

In this example I get the path:

/TBR-theme-202311/images/hero/TBR-angela6-pink-tom9-yellow-1800x450px.jpg

Does that work for you?

Mike

Here to learn more about HubSpot and share my HubSpot Knowledge. I’m the founder of Webalite a HubSpot Partner Agency based in Wellington, New Zealand and the founder of Portal-iQ the world’s first automated HubSpot Portal Audit that helps you work smarter with HubSpot.