I have been trying to have some blocks with collapsible content, but to put them in cms blocks so the text can be maintained by a normal human
I have found, thanks to previous stack discussions, that the syntax in the magento documentation needs extra quoting for it to save properly. It works. BUT IT ONLY WORKS FOR ONE SAVE, THEN IT BREAKS
<div data-mage-init='{"accordion":{"openedState": "active", "collapsible": "true", "active": "1", "multipleCollapsible": "false"}}'>
<div data-role="collapsible">
<div data-role="trigger">
Title 1
</div>
</div>
<div data-role="content">
<p>
Content 1 bla bla bla.
</p>
</div>
<div data-role="collapsible">
<div data-role="trigger">
Title 2
</div>
</div>
<div data-role="content">
<p>
Content 2 bla bla bla.
</p>
</div>
If I put this in and save works fine on the front end
The problem I have is that the next time I open the editor, under the scenes the html has been changed to
<div data-mage-init="{"accordion":{"openedState": "active", "collapsible": "true", "active": "1", "multipleCollapsible": "false"}}">
and that, on saved, gets garbled to
<div data-mage-init="{">
which obviously will not work to trigger an accordion and will also break other elements which rely on data-mage-init and RequireJS
Note the same happens on a CMS page.
I have tried putting it as
<div data-mage-init="{"accordion":{"openedState": "active", "collapsible": "true", "active": "1", "multipleCollapsible": "true"}}">
and that, saved, also work - but on the next opening it too gets turned into
<div data-mage-init="{"accordion":{"openedState": "active", "collapsible": "true", "active": "1", "multipleCollapsible": "false"}}">
and breaks again.
So on an edit one must show source and fix that line, before saving, every time, else the block breaks.
Has anyone figured out how data-mage-init can be formatted to not break in a cms block?
putting the <div data-mage-init=...>
call in the "parent" content where the cms block is put in as a widget didn't work either - though a wrapper block calling that block did work. But that is a ridiculously unmaintainable option - as is creating a whole new widget and content editing section just so I can add content that uses a built in layout option!
I have considered creating a custom block template that would have the accordion code but then I lose the ability to set what tabs are expanded on open, or any other flexibility.
Is this truly impossible or can these data-mage entries work in cms content? How can i put a maintainable bit of accordion content in my pages?