When you install ContentQL locally, sample blog-related data (such as authors,
tags, blogs, and blog details) will be available by default. To start with a
clean slate without this sample data, follow the steps below. Otherwise, proceed
directly to Block Creation.
Open a new terminal window while running the local server.
Run the command pnpm run:seed. During the installation, you'll encounter the following prompt:
Select Yes to drop the existing database and start fresh.
Select No to prevent the random sample data from being seeded.
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:
Implement the UI for the block in component.tsx:
Export the slug and component in index.ts:
Import the block configuration and component into the main blocks/index.ts file:
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! ✨