'Shopware 6 - Add data to custom cms element

I need to add data to a custom cms element.

I followed along this tutorial https://hungmac.com/how-to-add-data-to-the-cms-element-in-shopware-6 and also read the documentation https://developer.shopware.com/docs/guides/plugins/plugins/content/cms/add-data-to-cms-elements but I weren't able to add some data.

Does anyone know if there is a missing part or the like which is not mentioned in both tutorials?

Here is what I tried so far:

I created a new class:


    class JobCmsDataResolver extends AbstractCmsElementResolver
    {
        public function getType(): string
        {
            return 'job-listing';
        }
    
        public function collect(CmsSlotEntity $slot, ResolverContext $resolverContext): ?CriteriaCollection
        {
            return null;
        }
    
        public function enrich(CmsSlotEntity $slot, ResolverContext $resolverContext, ElementDataCollection $result): void
        {
            $slot->setData(ArrayStruct(['demo' => 'test']));
        }
    }

and edited my services.xml


    <service id="MyPlugin\DataResolver\JobCmsDataResolver">
        <tag name="shopware.cms.data_resolver"/>
    </service>

I added a {{ debug() }} to my cms file but didn't see the data I set in my php class



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source