Closed JorisOrangeStudio closed 1 month ago
Advanced SEO relies on an entry's augmented data in the cascade to compute its values. Additionally, SEO processing is opt-in for custom routes.
This will augment the entry's data, enable SEO processing, and add the entry to a scoped variable so you can do things like {{ entry:variable }}
.
Route::statamic('projects/{slug}/media', 'projects.media', function ($slug){
$entry = Entry::query()->where('uri', '/projects/' . $slug)->first();
return $entry->toAugmentedCollection()->merge([
'seo_enabled' => true,
'entry' => $entry,
])->all();
});
If you can live without the scoped entry
variable, you can simplify this to:
Route::statamic('projects/{slug}/media', 'projects.media', function ($slug){
return Entry::query()
->where('uri', '/projects/' . $slug)
->first()
->toAugmentedCollection()
->merge([
'seo_enabled' => true,
])
->all();
});
Hi, I'm making 2 different routes for each entry in a specific collection. So each entry will have 2 pages in the end. I'm using this native statamic way of rendering it.
This allows me to use the entry data like this:
{{ entry:variable }}
in the templates. But it is not appending SEO data of the 'original' page. When replacingreturn ['entry' => $entry];
with$entry->toArray()
to have alle the entry data directly in the view (withoutentry:
prefix) it is throwing this error:I made a partially workaround by merging a seoConfig array like this with the entry data.
Can we prevent this error from occurring? For now it works, but would be nice to have it working without the additional array (and use that only if we need to override the title).