Overview¶
In this article, we will integrate Catalog Menu with the Storyblok CMS. The integration will allow you to create and manage catalog navigation links in the Storyblok CMS and display them in the Virto Commerce vue-b2b-theme
.
With this guide, we will:
- Set up and create global componenet.
- Create catalog menu block.
- Create catalog menu content.
- Fetch content from Storyblok.
Set Up Global Component¶
To set up a folder in Storyblok:
-
Define a content type for the folder. Let's name it global as it will hold our global components. We should also ensure that the content type in the global folder cannot be changed, so that we only have entries of that type. Additionally, we should select the default content type option so that global is already chosen.
If you don't have a global content type, create it by clicking on the New content type button.
-
Create our first entry within the folder. When creating the entry, ensure that the content type is set to global as we have disabled the ability to change the content type for the folder. You can choose any name for the entry, but make sure it accurately describes the content of the global component to your editors. Since we are creating a Catalog Menu, which is in fact a megamenu, we will name the entry Megamenu.
-
Set up the actual field in the entry that holds our component. We will click Define and add a new field called global of the Blocks type.
Create Catalog Menu Block¶
To create a new block called megamenu:
- Go to the Block Library menu and click New Block in the top right corner.
- Enter the name of the component. We will enter Megamenu.
- Add a new field called items of type Blocks.
-
Click Save.
-
Since components in Storyblok have a block structure, we need to create blocks for each menu item and each menu link in the same way. For this, we will create the Megamenu-item block and the Megamenu-link-item block of the Nestable block type. The Megamenu-item block structure can be as follows:
The Megamenu-link-item block structure can be as follows:
-
Link all the blocks together to restrict the selection of external blocks that are not related to the megamenu:
- Go to the settings of each block to find the entry with the type Blocks in the General section and in the Edit field section.
- Check Allow only specific components to be inserted.
-
Choose the component that can be nested in this block. In our example, the nesting looks as follows:
Megamenu block configuration can be as follows:
The blocks have been created and their nesting has been configured.
Create Catalog Menu Content¶
To create the content for our Catalog Menu:
- Go to the Content menu and click on the Megamenu entry we created earlier.
-
Click on the Add Block button and select the Megamenu block.
-
Add the Megamenu-item block.
- Add the Megamenu-link-item block.
- Fill in the necessary fields for each block.
- Click Save to save the changes.
Fetch Content from Storyblok and Display in vue-b2b-theme¶
To fetch content from Storyblok and display it in the vue-b2b-theme:
- Go to the vue-b2b-theme and edit the
useNavigations
composable. Change thefetchCatalogMenu
method to fetch the Catalog Menu from Storyblok. - Replace the
getMenu
method call with theuseStoryblok
method call. -
Pass the path to our menu.
The Catalog Menu is now fetched from Storyblok and displayed in the vue-b2b-theme:
You can publish the changes and see the Catalog Menu in the vue-b2b-theme.