Table of contents
By chance, I came across a post in the forum that mentioned a bug in Shopware 6.5. This post mentioned the guides about the CMS-Block and the CMS-Elements I wrote a while ago. To keep it short, there is no bug in Shopware 6.5 - There was a bug in my code. So let's take a quick look at it.
The Shopware Forum
There is a Shopware forum where you can find a lot. People are discussing, searching for help or people just sharing their knowledge. From time to time I take a look at the forum as well because sometimes you can help some people or maybe you want to ask something yourself.
However, this time it was different. I found a post that mentioned a bug in the Shopware CMS. So I took a look at this forum post and noted someone mentioned my blog posts.
At that time the bug was already fixed in the forum post as well - I just made a simple mistake. I haven't tested the code in Shopware 6.5 to that time and somehow the code works with Shopware 6.4. However, it was still a great read because now I know my blog posts can help people.
Let's take a look at the code!
The Code
If you want to see the whole Code just take a look at this GitHub Repository.
The CMS-Block in the administration did not work. The same code that runs with Shopware 6.4 is not working on 6.5? A simple rebuild should fix this issue but it did not.
There was a small mistake in the naming when I registered the component. The index.js
looked like this
const { Component } = Shopware;
Component.register('sw-cms-button', {
template
});
This was a quick fix simply change the name of the registered component to:
const { Component } = Shopware;
Component.register('sw-cms-block-button', {
template
});
Now I also made a mistake when registering the block - It's also a small naming bug
import './preview';
Shopware.Service('cmsService').registerCmsBlock({
name: 'cms-button',
label: 'sw-cms.blocks.text.ninja-cms-button.label',
category: 'text',
component: 'sw-cms-block-button',
Here we have to register the name button
and that's it. Your file should look something like this:
import './preview';
Shopware.Service('cmsService').registerCmsBlock({
name: 'button',
label: 'sw-cms.blocks.text.ninja-cms-button.label',
category: 'text',
component: 'sw-cms-block-button',
Now the administration works again, great!
The frontend view
A small naming mistake can cause a lot of problems. The administration now works again but you don't get anything in the storefront.
It's still the same mistake. If you spell something wrong it can break everything. So let's fix that real quick as well. Since we renamed the block
we also have to rename that block
.
Go to src/Resources/views/storefront/block/cms-block-cms-button.html.twig
and simply rename it to src/Resources/views/storefront/block/cms-block-button.html.twig
.
Great now everything should work again!