Getting image widget source

SOLVE
Amit_95
Member | Platinum Partner

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 Accepted solution

Accepted Solutions
piersg
Solution
Key Advisor

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>

 

View solution in original post

4 Replies 4
amwilie
Key Advisor | Elite Partner

@Amit_95 Try :

{{ content.widget_data.listing_image.src }}

 

border

Alyssa Wilie

Web Developer at LyntonWeb

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

Amit_95
Member | Platinum Partner

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
Member | Platinum Partner

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
piersg
Solution
Key Advisor

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>

 

View solution in original post