BBC's guide to development
  • General

    • About
    • Tools
    • Git(hub)
    • Showpad
    • Hosting
    • Maintenance
    • Security
    • Go live checklist
  • Front-end development

    • Bundlers
    • CSS/SCSS
    • Javascript
    • Vue
    • PHP
    • Mails
    • Dev Faq
  • Functions
  • Mixins
  • General

    • OOP Structure
  • Component Classes

    • Accordion
    • App
    • Component
    • HighwayApp
    • Popup
    • PNG Sequencer
    • Tab
  • Manager Classes

    • BountListenerMgr
    • Cache
    • Configuration
    • InViewStateMgr
    • Instance Manager
    • Event dispatcher
  • Factories

    • SwiperFactory
  • PDF

    • AssetLoader
    • BasePdfDoc
    • TemplatePdfDoc
    • CustomPdfDoc
  • Utility functions

    • canvas
    • Connection Status
    • css
    • dev
    • placeholder
    • dom
    • fetch
    • json
    • object
    • scroll
    • scrollbar
    • spreadsheets
    • string
    • url
  • General

    • ComponentMgr
    • ThreeJsViewer
  • Components

    • ComponentMgr
    • GltfModel
    • Snappable
    • Socket
    • ThreeJsViewer
    • ThreeJsViewerCamera
  • Loaders

    • ConfigurationSerializer
    • GltfBlockParser
  • Utils

    • CanvasInputAdapter
    • CollisionManager
    • SocketGridExpander
    • blender
    • headless
  • General

    • Troubleshooting
    • Legacy
  • Components

    • AssetBar
    • ConfigGenerator
    • ShowpadApp
  • Managers

    • Assets
    • AppsDb
    • Config
  • Utils

    • Connection Status
    • general
    • showpad-interactive
    • showpad-upload
  • Components

    • Accordion
    • BackButton
    • Breadcrumb
    • ByltButton
    • Hamburger
    • Icon
    • Logo
    • Loader
    • Modal
    • Popup
    • Prompt
    • ProgressBar
    • TextLoader
  • Composables

    • useDebugMode
    • useConnectionStatus
  • Utils

    • dom
    • props
  • General

    • General
    • Tracking
  • Components

    • Accordion
    • ActionButton
    • AssetItem
    • AssetList
    • BackButton
    • ConfigGenButton
    • Logo
    • Media
    • Modal
    • Popup
    • Prompt
    • SPButton
    • SPRouterView
    • SPTrackedRouterLink
    • TextLoader
    • View
  • Composables

    • useConnectionStatus
  • Stores

    • useAppsDbStore
    • useBreadcrumbStore
    • useShowpadAPIStore
    • useShowpadSDKStore
    • useSpConfigStore
    • useSpStore
    • useSpTrackingStore
  • The New Kit

    • General
    • Installation & Usage
    • ACF Blocks
    • PHPCS
    • Functions
    • Vite
    • WP Config
    • Staging Deployment
  • Best Practices

    • Page Structure
    • Fonts/Typography
  • Todo
GitHub
  • General

    • About
    • Tools
    • Git(hub)
    • Showpad
    • Hosting
    • Maintenance
    • Security
    • Go live checklist
  • Front-end development

    • Bundlers
    • CSS/SCSS
    • Javascript
    • Vue
    • PHP
    • Mails
    • Dev Faq
  • Functions
  • Mixins
  • General

    • OOP Structure
  • Component Classes

    • Accordion
    • App
    • Component
    • HighwayApp
    • Popup
    • PNG Sequencer
    • Tab
  • Manager Classes

    • BountListenerMgr
    • Cache
    • Configuration
    • InViewStateMgr
    • Instance Manager
    • Event dispatcher
  • Factories

    • SwiperFactory
  • PDF

    • AssetLoader
    • BasePdfDoc
    • TemplatePdfDoc
    • CustomPdfDoc
  • Utility functions

    • canvas
    • Connection Status
    • css
    • dev
    • placeholder
    • dom
    • fetch
    • json
    • object
    • scroll
    • scrollbar
    • spreadsheets
    • string
    • url
  • General

    • ComponentMgr
    • ThreeJsViewer
  • Components

    • ComponentMgr
    • GltfModel
    • Snappable
    • Socket
    • ThreeJsViewer
    • ThreeJsViewerCamera
  • Loaders

    • ConfigurationSerializer
    • GltfBlockParser
  • Utils

    • CanvasInputAdapter
    • CollisionManager
    • SocketGridExpander
    • blender
    • headless
  • General

    • Troubleshooting
    • Legacy
  • Components

    • AssetBar
    • ConfigGenerator
    • ShowpadApp
  • Managers

    • Assets
    • AppsDb
    • Config
  • Utils

    • Connection Status
    • general
    • showpad-interactive
    • showpad-upload
  • Components

    • Accordion
    • BackButton
    • Breadcrumb
    • ByltButton
    • Hamburger
    • Icon
    • Logo
    • Loader
    • Modal
    • Popup
    • Prompt
    • ProgressBar
    • TextLoader
  • Composables

    • useDebugMode
    • useConnectionStatus
  • Utils

    • dom
    • props
  • General

    • General
    • Tracking
  • Components

    • Accordion
    • ActionButton
    • AssetItem
    • AssetList
    • BackButton
    • ConfigGenButton
    • Logo
    • Media
    • Modal
    • Popup
    • Prompt
    • SPButton
    • SPRouterView
    • SPTrackedRouterLink
    • TextLoader
    • View
  • Composables

    • useConnectionStatus
  • Stores

    • useAppsDbStore
    • useBreadcrumbStore
    • useShowpadAPIStore
    • useShowpadSDKStore
    • useSpConfigStore
    • useSpStore
    • useSpTrackingStore
  • The New Kit

    • General
    • Installation & Usage
    • ACF Blocks
    • PHPCS
    • Functions
    • Vite
    • WP Config
    • Staging Deployment
  • Best Practices

    • Page Structure
    • Fonts/Typography
  • Todo
GitHub
  • ConfigGenerator

ConfigGenerator

import { buildConfig } from '@bbc/front-end-kit/js/showpad/managers/ConfigGenerator';

Generates a config.json skeleton by scanning the DOM for Showpad data attributes. Eliminates the manual work of listing fields and maintaining the correct JSON structure during development.

Tips

When active, label injection is suppressed so the element's default HTML content is shown instead of config values — useful for seeing placeholder text while building.

Warning

The generated config object lives in memory only. It resets on full page reload. This tool works best in single-page router setups (e.g. HighwayApp) where the page does not fully reload between views.

Tips

buildConfig adds a --config-gen modifier class to document.body. Use it to trigger developer-only CSS that highlights config paths or missing values during setup.

Getting started

import { buildConfig } from '@bbc/front-end-kit/js/showpad/managers/ConfigGenerator';
import ShowpadConfig from '@bbc/front-end-kit/js/showpad/managers/Config';

const config = new ShowpadConfig();

config.load().then(() => {
    const result = buildConfig(config);
    console.log(result); // copy-paste this into config.json
});

The result is logged to the console as a JavaScript object — copy and paste it into your config.json file.

Config field description

Add data-sp-description to provide a description for a field in the generated config. Add data-sp-required to append an asterisk (*) to the description, marking it as required.

<div data-sp="path.to.field"
     data-sp-required
     data-sp-description="Small description">
    Default value
</div>

Generates:

{
    "labels": {
        "path": {
            "to": {
                "field": {
                    "value": "Default value",
                    "description": "Small description *"
                }
            }
        }
    }
}

This also works for data-sp-asset types — the generated structure will use the appropriate asset shape (asset, multitype, tags, asset-tags, page-tags).

API

buildConfig(configInstance, options = {})

Scans the DOM for all elements with Showpad data attributes and builds a config object incrementally. Adds --config-gen to document.body. Consecutive calls to buildConfig merge into the same internal module-level object — entries are accumulated across calls, not replaced.

Parameters

  • configInstance (Config): The ShowpadConfig instance. Used to resolve attribute names and process placeholders.
  • options (object, optional):
    • $el (Element, default document.body): Scope root — only elements within this element are scanned.

Returns

object — the accumulated config object with version, labels, and contents.

Singleton accumulator

config is a module-level variable. Every buildConfig call adds to the same object. If you need a fresh config, reload the page or call buildConfig only once per session.

External dependencies

  • Config: Provides getAttributeSelector() and extractPathInfo() for DOM scanning.
  • lodash-es get / set / camelCase: Path traversal and writing into the generated config object.
Edit this page
Last Updated: 4/27/26, 12:56 PM
Contributors: Nicolas Jaenen