On this Page
- Board Game card design
- Board Game fields
- Create Category
- Create Board Game Section
- Create an Asset Volume
- Create the Board Game Fields
- Create Field Group
- Add Image field
- Add Category field
- Add Number of Players fields - Min, Max & Best
- First glance at Board Game entry form
- Field Layout
- Field Layout - UI Elements
- Duration fields
- Add Minimum Duration
- Add Maximum Duration
- Duration - Field Layout
- Add Difficulty field
- Difficulty - Field Layout
- Add Play Online field
- Play Online - Field Layout
- Add Image to Field Layout
- Create our first board game entry
This article is part of a series on building a favorite board games library in Craft CMS. In this lesson, we’ll create the Board Games section.
Board Game card design #
Eventually, we’ll build a board game card that looks like this:
There’s a fair amount of data packed on that little card. Let’s break down the fields & data types we’ll need.
Board Game fields #
Field Name | Data Type |
---|---|
Image | |
Category | category |
Title | text |
Minimum number of players | number |
Maximum number of players | number |
Best number of players | number |
Minimum Duration (minutes) | number |
Maximum Duration (minutes) | number |
Difficulty | dropdown |
Play Online? | link |
Create Category #
Let’s start by creating the Category for our board games. The Notion spreadsheet shows that it only has 3 values: Strategy, Family & Abstract.
- Go to Settings.
- Click on Categories.
- Click the New category group button.
- Fill out the Name field with “Board Games”.
Craft CMS automatically fills in the Handle and URI format. The Handle value boardGames is fine but I’m going to change the URI format to category/{slug}.
If our site also had Video Games it might make sense to make the category URLs more specific. But here I prefer a generic category URL to avoid confusion with board game listing or detail pages. - Click Save.
- Click Manage categories.
- Click the New category button.
- Enter “Strategy”.
From the drop-down select Save and add anotherShift-Command-S
.
Enter “Family”.Shift-Command-S
.
Enter “Abstract”. - Click Save.
We now have the Board Game category with 3 values.
Create Board Game Section #
A Craft CMS Section is similar to a content type in other CMSs. Craft has 3 types of Sections: Singles, Channels and Structures. 1
In our case either a Channel or Structure would work. But I’m going to go with Channel since a Structure is more appropriate for content with hierarchy like Book Chapters.
- Go to Settings.
- Click on Sections.
- Click the New section button.
- Fill out the Name field with “Board Games”.
The default Handle value boardGames is fine. And I’ll leave the Section Type as Channel. The only change I’ll make is to the URI Format where I’ll remove the hyphen boardgames/{slug}. - Click Save.
Create an Asset Volume #
We need a place to store our board game cover image, which means we need to create an asset volume.
- Go to Settings.
- Click on Assets.
- Click New volume button.
- Fill out the Name field with “Board Games”.
- Enable Assets in this volume have public URLs
- In Base URL enter @web/uploads/images/boardgames
- Leave Volume Type as Local Folder.
- In File System Path enter @webroot/uploads/images/boardgames
- Click Save.
To mitigate a security concern, it’s best to explicitly set the @web alias in config/general.php
2
'aliases' => [
'@web' => getenv('DEFAULT_SITE_URL'),
],
To ensure we’ve setup our asset volume correctly, let’s upload a test image.
- Go to Assets.
- Click on Board Games.
- Click Upload files button.
- Select a test image from your local files.
Create the Board Game Fields #
We can finally start adding fields to our Board Games channel. We start by creating a Field Group.
Create Field Group #
- Go to Settings.
- Click on Fields.
- Click on + New group button.
- Enter “Board Games” in the alert dialog.
- Click OK.
Add Image field #
- Go to Settings> Fields.
- Click on Board Games field group.
- Click on New field button. Notice how the Board Games group is pre-selected.
- Fill out the Name field with “Board Game Image”. The default Handle value boardGameImage is fine.
- In Field Type select Assets. Check Restrict uploads to a single folder And leave the default value.
- Also check Restrict allowed file types and select Image.
- Set Limit to 1.
- For View Mode select Large Thumbnails.
- In Selection Label enter “Add a board game image”.
- Click Save.
Add Category field #
- Go to Settings> Fields.
- Click on Board Games field group.
- Click on New field button.
- Fill out the Name field with “Board Game Category”. The default Handle value boardGameCategory is fine.
- In Field Type select Categories.
- In Source select Board Games
- In Branch Limit enter “1” so that only one category be assigned to board games.
- Click Save.
Add Number of Players fields - Min, Max & Best #
The next 3 fields are basically the same, a whole number for the minimum, maximum and best number of players.
For the following steps, you should already in the Board Games field group.
- Go to Settings> Fields.
- Click on Board Games field group.
Minimum
- Click on New field button.
- Fill out the Name field with “Minimum number of players”. Shorten the Handle value to minNumPlayers.
- In Field Type select Number.
- Enter the following values in corresponding fields.
Default: 1
Min: 1
Max: 2 - Click Save.
Maximum
- Click on New field button.
- Fill out the Name field with “Maximum number of players”. Shorten the Handle value to maxNumPlayers.
- In Field Type select Number.
- Enter the following values in corresponding fields.
Default: 4
Min: 2
Max: 10 - Click Save.
Best
- Click on New field button.
- Fill out the Name field with “Best number of players”. Shorten the Handle value to bestNumPlayers.
- In Field Type select Number.
- Enter the following values in corresponding fields.
Default: 2
Min: 2
Max: 10 - Click Save.
First glance at Board Game entry form #
Let’s take a break from adding fields and check how the admin form to create a board game is coming along.
- Click on Entries.
- Click on Board Games.
- Click New entry button. And you’ll see a screen like this:
That’s strange… we only see a Title field. π€
Well there’s an additional step to make fields available on this admin entry form.
Field Layout #
- Go to Settings.
- Click on Sections.
- Click on Edit entry types (1).
Click on Board Games.
Welcome to Craft’s Field Layout builder, a drag-n-drop interface to build your admin entry forms.From the right sidebar, drag Category and put it underneath Title.
- Put the 3 number of player fields underneath Category. In this order: Min, Max and Best.
- Set the width for each player field to 25%.
- Click Save.
Refresh the create an entry form and it should now look like this:
Pretty good. But I don’t like how number of players is repeated on the 3 player fields. So I’m going to use Field Layout’s UI tools to clean this up a bit.
Field Layout - UI Elements #
- Return to the Field Layout for Board Games.
- Click on the UI Elements tab.
- Drag a Heading element under Category.
- Click on the gear icon βοΈ and enter “Number of Players” Click Apply.
- Click the gear icon βοΈ for Minimum number of players. In the Label field enter “Minimum”. Also, make it Required.
- Click Apply.
- Click Save.
Repeat for Maximum number of players and Best number of players.
Return to the create an entry form and it should now look like this:
I think that looks a bit cleaner. Let’s add the remaining fields.
Duration fields #
Once again for the following steps, you should already in the Board Games field group.
- Go to Settings> Fields.
- Click on Board Games field group.
Add Minimum Duration #
- Click on New field button.
- Fill out the Name field with “Minimum Duration”. Shorten the Handle value to minDuration.
- In Default Instructions enter “in minutes”.
In Field Type select Number.
Enter the following values in corresponding fields.
Default: 30
Min: 5
Max: 180- Click Save.
Add Maximum Duration #
- Click on New field button.
- Fill out the Name field with “Maximum Duration”. Shorten the Handle value to maxDuration.
- In Default Instructions enter “in minutes”.
In Field Type select Number.
Enter the following values in corresponding fields.
Default: 60
Min: 30
Max: 600- Click Save.
Duration - Field Layout #
- Return to the Field Layout for Board Games.
- Add the Duration fields similar as how we added the Number of Player fields.
The entry form should now look like this:
Time to add the Difficulty field.
Add Difficulty field #
- Go to Settings> Fields.
- Click on Board Games field group.
- Click on New field button.
- Fill out the Name field with “Difficulty”. The default Handle difficulty is fine.
- In Field Type select Dropdown.
- In Dropdown Options> Option Label column, enter “Easy”, “Medium” and “Hard”. Set Easy as the default.
- Click Save.
Difficulty - Field Layout #
- Return to the Field Layout for Board Games.
- Drag Difficulty below Category.
- Set the width for both to 25%.
- Click Save.
The entry form should now look like this:
Now let’s add the Play Online field.
Add Play Online field #
- Go to Settings> Fields.
- Click on Board Games field group.
- Click on New field button
- Fill out the Name field with “Play Online”. The default Handle playOnline is fine.
- In Default Instructions enter βEnter URL where game is available to play online.β.
- In Field Type select URL.
- Click Save.
Play Online - Field Layout #
- Return to the Field Layout for Board Games.
- Drag Play Online below Maximum Duration.
- Click Save.
The entry form should now look like this:
1 more field left! We just need to add the board game cover image to the field layout.
Add Image to Field Layout #
- Return to the Field Layout for Board Games.
- Drag Board Game Image below Title.
- Set the width to 25%.
- Click Save.
The entry form in its final glory should look like this:
Create our first board game entry #
Let’s add our first board game!
We’re going to add the excellent card game β Race for the Galaxy.
- Click on Entries.
- Click on Board Games.
- Click the New entry button.
- Enter “Race for the Galaxy” for the Title
- Download and use this image for the Board Game Image.
- Select Strategy for Category.
- Select Medium for Difficulty.
- For Number of Players enter: 2, 4, 2 (min, max, best).
- For Duration, the default values work (min 30, max 60).
- In Play Online enter: https://boardgamearena.com/gamepanel?game=raceforthegalaxy
- Click Create.
Nice! We have our first board game entry created.
In the next lesson, we’ll import the rest of our board games using Craft’s first party import plugin β Feed Me.
-
Github source code: config/general.php. β©