How to get config variables from custom cms-block on frontend

Hi! I create custom CMS-Element from this tutorial:
Add CMS Element
I can set in config-input field some video ID from dailymotion.com, it works nice.
On frontend it renders from twig file - /src/Resources/views/storefront/element/cms-element-dailymotion.html.twig, it also works nice. I see, that in this twig file I get saved video-ID via {{ element.config.dailyUrl.value }}, perfect!
But, for put this CMS Element to some Layout - I need drag-drop in Layout-editor some other CMS-Block from right and then I must replace it for my Dailymotion-element. Logically, it will be good to create some CMS-Block for Dailymotion, because I want see it in right side in Layout editor.

So, I have create new CMS-Block reading this tutorial:
Add custom CMS blocks
I puted it in video-category of blocks.
Now I see this block in right side of Layout-editor under video-category, I can drag-drop it to layout and configuring it with video-id. In admin side it still works nice, I see, how movie changes when I change video-id and I can save it - it works.
If I use my new CMS-Block for Dailymotion - I must use other twig file on frontend: /src/Resources/views/storefront/block/cms-block-dailymotion.html.twig
But in it I can’t get {{ element }} object, so, this way with CMS-Block does not work.
When I try dump element object ({{ dump(element) }}) - I get null
Ok, then I try {{ dum(block) }} - I see necessary vatiable deep in block.slots.elements[„ElementID“].config[„dailyUrl“][„value“]
But it is bad way, because ElementID changes from element-to-element.

So, my question is - how can I get my config variable on frontend in twig-file, when I use CMS-Block instead CMS-Element?

My question here is somewhat related but as you can see this whole custom CMS block/element topic is also still WIP for me.
In your case the solution is probably to take the approach of the core template files and set {% set element = block.slots.getSlot('slot_name') %} first. Thus, this block-object is not well documented and still a mistery to me.

1 Like

Nice, thanks a lot, it helps me. Now I can use my config variables on frontend!

1 Like