CMS Development

Amit_95
Participante | Partner nivel Platinum
Participante | Partner nivel Platinum

Getting image widget source

resolver

I have the following line of code on my blog post template

 

{% image "listing_image" label="Listing image", export_to_template_context=True %}

 

The featured image on a blog post is used in the hero section. I have created this image widget so that a user can select a smaller image that can be used on the listing template.

 

To get the above widgets value, I'm doing the following:

 

{% for content in contents %}
{{ content.widgets.listing_image.body.value.src }}
{% endfor %}

 

However, the value it returns is empty. I have also tried:

 

{{ content.widgets.listing_image.body.value }}

 

Same results, it is empty.

 

How do I get the value of the widget on my post template and use it on the listing template?

0 Me gusta
1 Soluciones aceptada
piersg
Solución
Asesor destacado

Getting image widget source

resolver

Hi @Amit_95, you just need to keep the body:

 

{{ content.widgets.listing_image.body.src }}

 

 

If you're not getting the result/data you expect it's sometimes helpful to console log a part of a method/dict which will help you find the structure you need to get what you want. e.g. the below will console log the widget data which you can then read to find out which object src is in.

 

<script>
  console.log(`{{ content.widgets.listing_image }}`);
</script>

 

Ver la solución en mensaje original publicado

4 Respuestas 4
piersg
Solución
Asesor destacado

Getting image widget source

resolver

Hi @Amit_95, you just need to keep the body:

 

{{ content.widgets.listing_image.body.src }}

 

 

If you're not getting the result/data you expect it's sometimes helpful to console log a part of a method/dict which will help you find the structure you need to get what you want. e.g. the below will console log the widget data which you can then read to find out which object src is in.

 

<script>
  console.log(`{{ content.widgets.listing_image }}`);
</script>

 

alyssamwilie
Experto reconocido | Partner nivel Elite
Experto reconocido | Partner nivel Elite

Getting image widget source

resolver

@Amit_95 Try :

{{ content.widget_data.listing_image.src }}

 

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
Amit_95
Participante | Partner nivel Platinum
Participante | Partner nivel Platinum

Getting image widget source

resolver

Hi amwilie,

Having what you suggested (below) didn't work for me either. The below returned nothing for me

 

{{ content.widget_data.listing_image.src }}
0 Me gusta
Amit_95
Participante | Partner nivel Platinum
Participante | Partner nivel Platinum

Getting image widget source

resolver

For reference, here is my blog post with a listing image populated. This post is published and updated so it should have a value.

 

Screenshot 2020-11-13 at 09.42.54.png

 

On my listing page, I have the following:

 

Screenshot 2020-11-13 at 09.45.09.png

 

But when inspecting that blog post card on the listing page, I see this:

 

Screenshot 2020-11-13 at 09.45.57.png

 

No value seems to pull through

0 Me gusta