Home App Docs Blog Github

How to control my page layout by adding custom Element?

Builder content link
e.g. Builder.io: Drag and drop page builder and CMS

Builder public api key

What are you trying to accomplish

I wanna add a custom WrapperComponent which should be able to control the (parent) layout (eg: hide Navigation, layout width/boxed, ON/OFF sidebars…etc. ). The component itself sits within this stack.

  • Layout
    • Header
    • Navigation
    • Content
      • SomeSidebar
      • MainContent
    • Footer

That component then also could take child elements. (Using Your React Components in Builder.io - Builder.io)

Code stack you are integrating Builder with

Reproducible code example
If you are having integration errors, please link to codesandbox or copy and paste your problematic code here. The more detail the better!

How to accomplish that? Are there examples for such cases?

Thank you

Hey @jezekjancom - one common way to accomplish this is with custom fields

E.g. add fields to your page like showNavigation that is a boolean, layoutWidth that is a number etc

then you can do like

import { BuilderComponent, BuilderContent, builder } from '@builder.io/react'

export const getStaticProps = async () => {
  const page = await builder.get('page', ...);
  return { props: { page } }

export default ({ page }) => {
  return ( 
    // This wrapper allows real time previewing of changing the custom field values like show/hide nav
    <BuilderContent model="page" content={page}>{page => 
      // Your layout component that you pass in the custom fields
     <MyLayoutComponent showNavigation={page.data.showNavigation} layoutWidth={page.data.layoutWidth}>
       // Render the rest of the Builder page content
       <BuilderComponent model="page" content={page} />