-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<image> data #60
Comments
You can certainly override the twig template in your theme to add any functionality you want. However please note you should test it to make sure it's still a valid feed or your users might not be able to consume it. |
Thanks |
Ciao, did you manage to include images in RSS? a colleague created a plugin for WP to just add the image, https://github.com/lesion/add-img-to-feed - still looking for a viable solution for grav. We manage to display images into grav feeds using PHP8 + TwigFeed beta https://github.com/OleVik/grav-plugin-twigfeeds/releases/tag/v5.0.0-beta.2 but the necessary twig is far from good - using item.content instead of item.medias - any idea will be appreciated, tnx. |
If you are asking about an img that is highlighted for each post, that's already being done via the this gets the first image from the page the entry is based on: https://github.com/getgrav/grav-plugin-feed/blob/develop/templates/feed.rss.twig#L20 and this displays it if it's available: https://github.com/getgrav/grav-plugin-feed/blob/develop/templates/feed.rss.twig#L28-L30 If you wanted to provide another image, or provide a URL you could simply add some custom header to the page. Depending on if you want to specify an image in the page folder, or an image in the site 'somewhere' or even an external image, you could override the feed.rss.twig file in your theme and replace the Assuming you specify an external in your page header like this: feed:
image: https://source.unsplash.com/gySMaocSdqs/1200x800 or a local image via stream like this: feed:
image: user://images/foo.jpg
and then copy and modify the {% set banner_file = item.header.feed.image %}
{% banner_file %}
{% if banner_file starts with 'http' %}
{# assume external file and just pull the img in as-is #}
{% set banner = '<img src="' ~ url(banner_file) ~ '" alt="featured img" />' %}
{% else %}
{# assume a local file via a stream and we'll use media to load image to allow resizing #}
{% set banner = media[banner_file].cropZoom(1200,800).html|absolute_url %}
{% endif %}
{% else %}
{# fallback is to grab first page image and resize it #}
{% set banner = cropZoom(1200,800).html|absolute_url %}
{% endif %} Then we just need to update the bit where it outputs a little as we now resize the image in the variable definition above: <![CDATA[
{% if banner %}
{{ banner|raw }}
{% endif %} Something like that. Not tested, but you get the idea. |
ciao, many thanks for your contribution! great! I was tinkering with, but you make it far more easier. Still, the grav rss template is good for us, but, for our purposes it lacks an enclosure for the image or even better for a media:image tag because right now, AFAIK, it includes the image into the content and it's not trivial to pick it up - somethin like a safe_truncate_html from content as in grav-plugin-feed/templates/feed.rss.twig Line 31 in 13606c7
this was the main reason leading us to re-code another WP plugin, add just a media:image |
Is there a way to modify feed.rss.twig to include a feature image for the RSS feed?
The text was updated successfully, but these errors were encountered: