# Accessing custom CMS blocks content in Twig

**URL:** https://forum.shopware.com/t/accessing-custom-cms-blocks-content-in-twig/90948
**Category:** Shopware 6 (English)
**Created:** [18. Oktober 2021 um 23:19 UTC](https://forum.shopware.com/t/accessing-custom-cms-blocks-content-in-twig/90948 "2021-10-18T23:19:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jonas.joachim](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jonas.joachim](https://forum.shopware.com/u/jonas.joachim)
#### Post date: [18. Oktober 2021 um 23:19 UTC](https://forum.shopware.com/t/accessing-custom-cms-blocks-content-in-twig/90948/1 "2021-10-18T23:19:14Z")

</div>

I’ve implemented three custom CMS blocks via the official way in a plugin.  
However, I need to make the content of the via Shopping Experiences added and administered blocks available in Twig templates also.  
My approach: Using the cms\_blocks repository with a ContainsFilter on ‚type‘ containing the type of the mentioned blocks. This works fine but I’m struggling with finding a solution to fetch the content of the slots of the blocks in order to make it available via a Twig extension in templates later. Is there a cleaner way to do this other than injecting the cms\_slots repository on top and using the fetched ids of the custom blocks within an EqualsAnyFilter and cascaed down the object hierarchy in order to access the desired content attribute? Do I need a custom Data Resolver in order to implement this feature in a convenient way?  
The WIP feature is currently implemented as a GenericPageLoadedEvent subscriber.

---

<div class="post-metadata">

### Author: ![jonas.joachim](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jonas.joachim](https://forum.shopware.com/u/jonas.joachim)
#### Post date: [19. Oktober 2021 um 03:02 UTC](https://forum.shopware.com/t/accessing-custom-cms-blocks-content-in-twig/90948/2 "2021-10-19T03:02:59Z")

</div>

Subscriber:

```auto
$criteria = new Criteria();
$criteria->addAssociation('block');
$criteria->addFilter(new ContainsFilter('block.type', 'desired-blocktype'));
$cmsSlots = $this->cmsSlotRepository->search($criteria, $event->getContext());

$event->getPage()->addExtension('cms_slots', $cmsSlots);

```

Twig:

```auto
{% for cms_slot in page.extensions.cms_slots %}
        {{ cms_slot.translated.config.content.value }}
{% endfor %}

```

---

<div class="post-metadata">

### Author: ![jonas.joachim](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jonas.joachim](https://forum.shopware.com/u/jonas.joachim)
#### Post date: [26. Oktober 2021 um 08:29 UTC](https://forum.shopware.com/t/accessing-custom-cms-blocks-content-in-twig/90948/3 "2021-10-26T08:29:41Z")

</div>

While the general work with the repositories is working out fine I’m now stuck with the problem of not having the cms\_slots in the desired order like in backend (createdAt and updatedAt sorting are implemented but not reliable). What is the recommended approach for that? I’ve checked also the core source and every usage of the addSorting method but honestly don’t know which field is used by Shopware itself to maintain an accurate order of the slots.
