steve
July 8, 2024, 6:40pm
1
I wanted to make use of load_data
to fetch a remote XML file:
https://pixelfed.scot/users/steve.atom
So I have:
{% set response = load_data(url="https://pixelfed.scot/users/steve.atom", format="xml") %}
What I’m struggling with now is how to process the response. If I try to output it I just get [Object]
.
I’m sure this is very simple, but I’m struggling to get my head round it. Any pointers? Thanks!
keats
July 9, 2024, 7:27am
2
This is going to be converted to a object matching the XML format. No way to pretty print it right now sadly (it does work as expected in tera v2) so it is trial and error
steve
July 9, 2024, 7:52am
3
Thanks for the reply!
No issue printing it out as I can view the raw XML, however I just can’t work out the syntax for accessing the data - is there an example it the docs anywhere?
Sorry for what is probably a very basic question!
keats
July 9, 2024, 8:02am
4
Something like response["your_field"]
should work
steve
July 9, 2024, 8:39am
5
Ah, that’s got me closer, I was missing the quotes.
So the part I’m trying to loop over (looking at the XML) is the “entry” part, which looks like this:
<entry>
<media:content url="xxx">
</entry>
All I really want out of this is the image URL from that <media field.
If I do this:
{% for entry in response["feed"]["entry"] %}
{{ entry }}
{% endfor %}
I just get:
Tried to iterate using key value on variable `response["feed"]["entry"]`, but it is missing a key