Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

FeedController.php chokes on title #2513

Open
herrajon opened this issue Apr 17, 2020 · 0 comments
Open

FeedController.php chokes on title #2513

herrajon opened this issue Apr 17, 2020 · 0 comments

Comments

@herrajon
Copy link

Howdy Folks

Sea trialing this smart looking flat filed WCMS. Love it. We could have future together.

Ventured off into to creating a json-feed based on instructions here (How to use a controller to create a JSON feed).

Done everything by the book, but it breaks when I add title to the soup. If I let that alone then it renders nicely the content and URLs.

I must be missing something obvious or have things changed since the docs were written?

It franticly complains about: "Undefined property: Statamic\Data\Entries\Entry::$title"

Code from FeedController.php

(Added title to the getItems function and the Statamic\API\Entry line)

<?php

namespace Statamic\SiteHelpers;

use Statamic\Extend\Controller as AbstractController;
use Statamic\API\Entry;

class FeedController extends AbstractController
{
    /**
     * @return mixed
     */
     public function json()
     {
         return [
             'version' => 'https://jsonfeed.org/version/1',
             'title' => 'My Awesome Site',
             'home_page_url' => 'https://my-awesome-site.com/',
             'feed_url' => 'https://my-awesome-site.com/feed.json',
             'items' => $this->getItems()
         ];
     }

     private function getItems()
     {
         return Entry::whereCollection('content-template')->map(function ($entry) {
             return [
                 'id' => $url = $entry->url(),
                 'url' => $url,
                 'title' => $entry->title,
                 'content_html' => markdown($entry->content()),
             ];
         })->all();
     }
}

Truly
Herra Jón

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant