3

So I'm using FeedMe to get RSS atom feeds and this is working O.K. But there's this field that has an attribute I want to extract. And I cannot get this to work.

In the FeedMe documentation it says:

For example, the XML <field my_attribute="Some Value">Another Value</field>, 
you can use {{ xml.field.attributes.my_attribute }}.

My field is called 'enclosure' and has an attribute called 'url' that I want to extract. According to the documentation, one would assume that this should work:

{% set feed = craft.feedme.feed(myfeed_rss) %}

{% for node in feed %}

    {
        'title': {{ node.title | raw }},
        'description': {{ node.description | raw }},
        'url': {{ node.link | raw }},
        'date': {{ node.pubdate | raw }},
        'image': {{ node.enclosure.attributes.url | raw }}
    }

{% endfor %}

Namely {{ node.enclosure.attributes.url }} should work? All the other fields are collected correctly. So it's just this one.

Edit: Btw, the feed I'm using is this one. http://www.adressa.no/?widgetName=polarisFeeds&widgetId=3185248&getXmlFeed=true

Edit2: Managed to get it to work, with help from crafw. Some of the nodes weren't empty, fixed it by changing the line to:

{{ node.enclosure.attributes.url|default('empty') }}

https://craftcms.stackexchange.com/users/632/crawf

RSS feed

3

I'm unable to view the feed via the link you've provided - seems like it may not allow public access. In any case, see a working example below using an example public RSS feed.

{% set params = {
    url: 'http://www.feedforall.com/sample.xml',
    type: 'xml',
    element: 'item',
} %}

{% set feed = craft.feedme.feed(params) %}

{% for node in feed %}
  {{ node.category.attributes.domain }}
{% endfor %}
  • Hmm, I see that the feedforall xml file is displayed in Chrome as an xml file. With expandable nodes. However in my own rss feed it's not rendered that way. Maybe that might be the issue. I updated my original post with a screenshot of my feed as opened in Chrome. – Kenny Bones Oct 21 '15 at 14:15
  • 1
    Yeah, I saw the same too - now that makes sense. Thats just likely the way its outputted. It may have something to do with it - it also could be that there is no inner-value for the enclosure node, so it ignores it. I'll have a test. – crawf Oct 21 '15 at 14:27
  • You were right, it was that some of the enclosure nodes was empty. I added a filter {{ node.enclosure.attributes.url|default('empty') }}. And it's working now :) – Kenny Bones Oct 21 '15 at 15:17
  • Awesome - I'll try to work this into the plugin - normally it would skip over nodes without an inner value, but it'll also need a check in there for attributes. Thanks! – crawf Oct 21 '15 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.