Next.js Discord

Discord Forum

Dynamic banners in layouts

Unanswered
Royal Tern posted this in #help-forum
Open in Discord
Avatar
Royal TernOP
Hey folks, I’m working on a site where pages can opt-in (through a CMS) to rendering a banner at the top of the page, above the navigation and brand logo.

Initially, I thought to put this inside the layout, but that would require the layout to a) know which page it’s wrapping, and b) use that information to fetch / determine whether a banner should be rendered.

The pattern of which pages do or don’t need a banner isn’t neat or predictable, and needs to be controlled via the CMS.

I have been prototyping a solution which involves checking banner requirements in middleware, then storing a cookie / using query parameters to get a message to the layout, which I can then use to control render.

It all sounds quite complicated for what should be a fairly simple feature.

Asking here in case I’ve missed the “obvious solution” - any help would be much appreciated 🙌

0 Replies