Next, we’ll demonstrate how to create
the above block, which includes a background image, heading, description, and
two buttons(primary, secondary). To start, create a folder inside
src/payload/blocks, and name it according to the block you’re creating. In
this case, we’ll call it Hero.
Define the configuration for the block in config.ts:
Import the component into the main blocks/blocks.ts file:
blocks/blocks.ts
import { DisqusComments } from '@contentql/core/client'import { Details } from './Details'import { Home } from './Home'import { List } from './List'import { Hero } from './Hero'export const blocksJSX = { Home, Details, List, Hero, }
Import the block configuration into blocks/config.ts file:
blocks/config.ts
import DetailsConfig from './Details/config'import HomeConfig from './Home/config'import HeroConfig from './Hero/config'import ListConfig from './List/config'export const blocksConfig = [HeroConfig, DetailsConfig, ListConfig, FormConfig]
You’ve successfully created a block! The types for it will be automatically
generated in payload-types.ts using the interfaceName defined in the
config.tsfile.
info
If types didn't auto-generated in payload-types.ts, run the following
command: pnpm generate:types
Once logged in to the admin panel, navigate to
the “Pages” section and create a new page. After providing a title, you’ll see
an option to add a “Page Layout.” All previously created blocks will appear in
this list with respective label names.
Now select hero block and save it. Once you fill in the field values, you can
now go to the page that you've created and see the magic! You’re now equipped to
create themes and blocks in ContentQL! ✨