Build your first theme
In this guide you create a theme from the starter, run it on your machine and change a block. Then you validate it and see it in Studio's page builder.
You need Node, pnpm and an Eldra organisation with the page builder switched on.
1. Create the theme
npx @eldrajs/theme-cli init my-site
cd my-site
pnpm installinit is the eldra-theme init command from @eldrajs/theme-cli. It copies the starter into my-site. The folder must be empty or not exist yet.
Everything it copies is your own source code. Change any of it. Only @eldrajs/ui stays an ordinary package you install and update.
What you get
my-site/
blocks/ one folder per block: block.json, Block.vue, mock.json
pages/ sample pages, also what a new site starts with
app/ the Nuxt app: layout, storefront code, helpers
i18n/ the theme's own words, in en-US and is-IS
tokens.json colours and layout widths merchants can change
stories/ Storybook stories (block stories are generated)
test/ page tests and accessibility checks
nuxt.config.ts loads @eldrajs/theme-nuxt
package.json scripts, and your theme id
.github/workflows/eldra-deploy.yml a deploy pipeline, if you build it yourselfThe starter also ships a .gitlab-ci.yml and a bitbucket-pipelines.yml. You need none of them when Eldra builds the site from your GitHub repository.
The important folder is blocks/. Each block is three files:
block.jsonlists the fields a merchant fills in.Block.vuerenders the block.mock.jsonis the content a block starts with when a merchant inserts it.
More: Starter kit conventions
2. Give your theme its id
Open package.json and find the eldra key:
"eldra": { "themeId": "starter", "defaultLocale": "en-US" }Change starter to a short name for your theme, such as shop. Use lower-case letters, digits and hyphens.
Choose the id once
Studio files your blocks and their content under this id. Changing it later makes a new theme as far as Studio is concerned. Two themes in one organisation need different ids.
More: Theme id and schema ownership
3. Connect it to your organisation
The theme reads content and products from your organisation. It needs two values:
ELDRA_GATEWAY_URL: your organisation's public API address.ELDRA_ORG_ID: your organisation id. Find it in Studio under Settings → API & tracking.
If your organisation has more than one website, also set ELDRA_SITE_ID. That is the site this theme builds. With one site, leave it out.
Register your dev address
Reading works from anywhere, but adding to the cart does not. Add http://localhost:3000 in Studio under Settings → General → Site addresses, in Other sites, so the cart works locally.
4. Run it locally
ELDRA_GATEWAY_URL=https://web-gateway.example.com ELDRA_ORG_ID=<org-id> pnpm devOpen http://localhost:3000. You see your organisation's published pages, drawn by your theme.
Without the two values, pnpm dev still starts. The commerce blocks just have nothing to show.
5. See your blocks in Storybook
pnpm storybookOpen http://localhost:6007. Every block has a story under Blocks, such as Blocks/hero. You get these stories for each block:
- Default: the block with its sample content and demo images.
- Inserted: the block exactly as it looks right after a merchant inserts it.
- One story per variant, when the block has a
variantfield.
You never write these stories. They are generated each time Storybook starts. The sample pages have stories too, under Pages.
More: Storybook and generated previews
6. Change a block
Open blocks/hero/mock.json and change the heading:
"heading": "Hello from my first theme",Save. The hero's Default story in Storybook updates, and so does the dev server. You do not need to restart either. The same goes for Block.vue, block.json, tokens.json and i18n/*.json.
Now try a field. Add one to blocks/hero/block.json, give it a value in mock.json, and read it in Block.vue. Then refresh the block types, so TypeScript knows the new field:
pnpm exec eldra-theme types --blocksTo start a block from scratch, scaffold it:
pnpm exec eldra-theme scaffold block my-blockRefresh the previews
Studio's block picker shows a picture of each block. After changing a block, run pnpm previews and commit the result. pnpm test fails while a picture is out of date. The first time, run pnpm exec playwright install chromium.
More: Blocks and fields
7. Validate
pnpm validateThis runs the same block check a build runs, with no connection needed. A good result looks like this:
OK — 35 blocks validOtherwise it lists each problem, names the block and field, and exits with an error. Fix them before you deploy. Commit .eldra/manifest.json, and it also warns about a field change that would break content merchants already wrote.
More: Validate
8. See it in the page builder
The page builder does not load your laptop. It loads your theme's deployed site. So deploy once, and the builder picks it up. The quickest way is to let Eldra build it from GitHub:
- Push the theme to a GitHub repository.
- In Studio, go to Content → Websites, press New website, then Connect to GitHub. Sign in, and pick the repository and branch.
- Press Create site and wait for the first build to finish.
- Open the page builder in Studio.
The first build adds your blocks to Studio and gives the site its starting pages. Insert a hero on a page. It arrives with the heading you wrote in mock.json. Select it and change its fields.
From now on, the loop is: change a block locally, check it in Storybook and the dev server, then push. Eldra builds the push, and the builder shows the new version when it is done.
Prefer to build it yourself? Deploy from your own pipeline with eldra-theme deploy.
Next
- Blocks and fields: write your own blocks and the fields merchants fill in.
- Pages, routes and menus: product pages, starting pages, links and languages.
- Styling and texts: make it look like the brand.
- Deploy and go live: how Eldra builds your site, and the CLI route.