statamic / seo-pro

An all-in-one site reporting, metadata wrangling, Open Graph managing, Twitter card making, sitemap generating, turn-key addon for Statamic.
https://statamic.com/addons/statamic/seo-pro
52 stars 33 forks source link

Add cascade hydration for custom route/controller/blade implementations #303

Closed jesseleite closed 7 months ago

jesseleite commented 7 months ago

Through a support request with a user, we found that they have a custom app logic in a custom route/controller/blade implementation to show an entry, which broke SEO Pro meta because it did not have the proper entry data hydrated through a more typical statamic view.

This PR allows them to manually add their entry content to the cascade like so...

class StoriesController extends Controller
{
    public function show(Entry $story)
    {
        // Add entry content to Statamic's view cascade...
        \Statamic\Facades\Cascade::withContent($story);

        // Custom app logic
        // ...

        // Return blade view
        return view('stories/story', [...]);
    }

Of course this is custom laravel app territory, but that's okay. The user will just need to be mindful about adding their entry content to the cascade in these scenarios where they bypass Statamic's typical route/controller/view flow 👍