I’ve added Bruno Meilick’s kirby3-feed plugin to my webcomic site using the Virtual Page configuration option, and it works great. I’m pulling the feed items directly from a collection that contains a filtered set of content from my site, and the feed is showing the item titles which, when clicked, redirect correctly to the relevant page on the site.
Each item in the feed is a comic strip, so I’d like to use the comic image as the description for each RSS entry. This is how I access the images currently:
for virtual pages you can extend your model to provide the text() method or create a new one like rssDescWithImg() and set 'textfield'=>'rssDescWithImg' in the config.
maybe the method must return a field-object so the rss snippet can invoke ->kirbytext() on it. but i never tested this.
When altering the feed options in the routes for the Feed plugin, I’d like to combine multiple page fields into one for the feed (ie.: I use the first image that is not in text field, author, categories, etc.). I gather you can do this using a snippet, but I need a more noob explanation on how this is possible.
If I try to set the feed to get the array coming from my allcontent controller I’m not sure I can apply the options to it to get all those field outputs. I hope I’m making sense.
I think a first step should be to create a custom collection for $allcontent. That way, you can easily pass this collection to the feed options.
Please rename your variables. Dashes are not allowed in PHP variable names. In the Kirby context, we use camelCase for readability, but you might as well use underscores to separate words/parts.
As regards combining multiple fields into one, you can use a custom page method or a page model that returns what you need.
Oh, thank you! Was just browsing other feed configuration solutions and noticed someone else was referencing Collections, which I haven’t made yet, so that might go a long way.
(Ah, those were dummy variables, I’ll fix them before someone else assumes they’re good. Thank you.)
Methods and models are beyond my understanding so far, but I will put those on my list to learn.
Thank you.
I’m trying to do this very same thing but am hitting a wall. I’m unsure how to combine the default text with the $page->file() in a format that the feed plugin wants (a field object, I guess?).
My PHP is super rusty. Am I missing something really basic?
class EntryPage extends Page {
public function text() {
$formattedImage = kirbytext('(image: ' . $this->file()->filename() . ' width: 400 srcset: [200, 400, 600])');
$unalteredText = parent::text();
// Combine $formattedImage and $unalteredText somehow.
// $textWithImage = ??
return $textWithImage;
}
}
public function rssDesc(): Field
{
$image = Html::img($this->file()->url());
$text = $this->text()->toBlocks();
return new Field($this, 'rssDesc', $image . $text);
}