CMS Development

Amit_95
Teilnehmer/-in | Platinum Partner
Teilnehmer/-in | Platinum Partner

Getting image widget source

lösung

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 Upvotes
1 Akzeptierte Lösung
piersg
Lösung
Autorität

Getting image widget source

lösung

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>

 

Lösung in ursprünglichem Beitrag anzeigen

4 Antworten
piersg
Lösung
Autorität

Getting image widget source

lösung

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
Trendsetter/-in | Elite Partner
Trendsetter/-in | Elite Partner

Getting image widget source

lösung

@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
Teilnehmer/-in | Platinum Partner
Teilnehmer/-in | Platinum Partner

Getting image widget source

lösung

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 Upvotes
Amit_95
Teilnehmer/-in | Platinum Partner
Teilnehmer/-in | Platinum Partner

Getting image widget source

lösung

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 Upvotes