I am creating a RSS feed from a news channel and I have gotten it all working except for the news story image which is an assets field. I want to pass the url of the image so I can pull it in via feed me into another craft site. I have looked and I can't find any examples of this working anywhere. Thanks for any help
2 Answers
If you want to just include the URL of the image in the feed so it can be picked up by Feed Me on another site, I believe you can use the <media:thumbnail>
tag:
<item>
<title>{{ entry.title }}</title>
<link>{{ entry.url }}</link>
...
<media:thumbnail url="{{ entry.myImageField.one().url }}" />
</item>
If you are using the template that Craft suggests. Then you can add the image into the tag. In my case the assets field is named "titleImage". I have a transform defined as "gallery" to resize the image down to a sensible size. I'm not sure if you need to include the width/height/alt of the image but I do in case it's useful to the feed reader. I'm not sure if different readers have different specs. This works in the Mac app NetNewsWire.
<description>
<![CDATA[
{% set image = entry.titleImage[0] ?? null %}
{% if image|length %}
<img src="{{ image.url('gallery') }}" alt="{{ image.caption }}" width="{{ image.getWidth('gallery') }}" height="{{ image.getHeight('gallery') }}">
{% endif %}
{{ entry.summary }}
]]>
</description>