Next.js Discord

Discord Forum

Single Layout

Answered
Selkirk Rex posted this in #help-forum
Open in Discord
Selkirk RexOP
I wanted to use a single layout similarly to this one from Vue that changes its title depending on what page your on.
Answered by B33fb0n3
you can use the template object inside your metadata, to generate a basic metadata. For all nested pages this metadata title is set. So if your template for example is "%s | Acme" all your sub pages have the default or it's own like "Own | Acme".

Take a look here: https://nextjs.org/docs/app/api-reference/functions/generate-metadata#template-object
View full answer

9 Replies

Selkirk RexOP
mine currently is using multiple layouts per page but kinda seems messy
the one with the red arrow is using a " use client " i can't seem to use metadata with it. I'm new so please bear with me
heres whats inside the layout ^
@Selkirk Rex I wanted to use a single layout similarly to this one from Vue that changes its title depending on what page your on.
you can use the template object inside your metadata, to generate a basic metadata. For all nested pages this metadata title is set. So if your template for example is "%s | Acme" all your sub pages have the default or it's own like "Own | Acme".

Take a look here: https://nextjs.org/docs/app/api-reference/functions/generate-metadata#template-object
Answer
@Selkirk Rex Is it possible to not use %s but instead use the name of the folders?
no. You need to explicity set the new title in the sub folder
@joulev