GenerateMetaData in Layout
Answered
LaPerm posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
LaPermOP
Does GenerateMetaData work in layout or just pages in Next13 app router? I am pulling my data in from a CMS and so I want default meta data. Does this not work on the layout file?
Or is there a way to pass a prop from the layout to all children components? If this doesn't work I can fetch the data in the layout function and pass it down somehow?
export async function generateMetaData(): Promise<Metadata> {
const { metaTitle, metaDescription, ogImage } = await sanityFetch<ISettings>({
query: settingsQuery,
});
return {
title: metaTitle ',
description: metaDescription,
openGraph: {
images: [ogImage.url],
},
};
}
Or is there a way to pass a prop from the layout to all children components? If this doesn't work I can fetch the data in the layout function and pass it down somehow?
8 Replies
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
it is
generateMetadata
not generateMetaData
Answer
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
LaPermOP
Ok so it is detecting the function but my title tag is not being set and the data definately is coming through.
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
LaPermOP
export async function generateMetadata(): Promise<Metadata> {
const { metaTitle, metaDescription, ogImage } = await sanityFetch<ISettings>({
query: settingsQuery,
});
return {
metadataBase: new URL('http://localhost:3000'),
title: {
default: metaTitle,
template:
},
description: metaDescription,
openGraph: {
images: [ogImage?.url],
},
robots: {
index: false,
},
};
}
const { metaTitle, metaDescription, ogImage } = await sanityFetch<ISettings>({
query: settingsQuery,
});
return {
metadataBase: new URL('http://localhost:3000'),
title: {
default: metaTitle,
template:
%s | ${metaTitle}
,},
description: metaDescription,
openGraph: {
images: [ogImage?.url],
},
robots: {
index: false,
},
};
}
this is on pages as well
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
ohh is that what you meant... i didn't realise you wanted the template...
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
LaPermOP
I am just trying different things to get it to show I don’t mind if it’s just title without template but no dynamic values are working