Can't render my custom seoData
Closed this issue · 2 comments
Hello,
This is probably very simple to resolve. I have set in my Blog model the function getDynamicSEOData
public function getDynamicSEOData(): SEOData
{
$language = app()->getLocale();
return new SEOData(
title: $this->{'title_'.$language},
description: $this->{'summary_'.$language},
author: 'Guy Verville',
image: $this->getFirstMedia('blog')('seo')
);
}
This looks fine.
In my BlogController in the show method, I wrote
$seo=$post->getDynamicSEOData();
[...]
return view('blog.show', ['content' => $content, 'seoData' => $seo]);
My blog template looks like this:
<x-layout>
<x-slot:title>{{ $content['title'] }}</x-slot:title>
<x-slot:translationURL>{{ $content['otherLanguage'] }}</x-slot:translationURL>
<x-slot:seoData>{{$seoData}}</x-slot:seoData>
<div class="relative pt-[100px] md:pt-[400px]">
[...]
</x-layout>
and my layout.blade.php has the {!! seo($seoData !!} or {{ seo($seoData) }} command. However, it get an error the it can pass your object, expects a string, etc.. {!! seo() !!} works fine, but with the default settings.
I have tried a lot of things, with no success. I have difficulty understand what should be passed. In other words, I get the SEO Object, but am unable to reproduce the examples given...
Can you help?
Hi @GuyVervillePerso, I see that you are echoing out the SEOData object, but you need to use the seo()
function instead:
{!! seo($SEOData) !!}
Hope that helps!
Thanks for the response, but I had tried this. I will create my own simple solution. :-)