I’m trying to preview the content of my custom blocks following the guide. So far displaying selected fields from the block works fine. The problem comes when the content of the block is another (nested) blocks field. I’ve come as far as to display the raw JSON of the (parent) blocks field, but I don’t know how to further parse it.
Thanks for your help, @scsskid! Indeed I had to take the computed value route to properly solve it.
Here’s the code I ended up with. elements is my nexted blocks field, so the code basically loops through all the children of elements and adds their field text to a string (with HTML tags) to be used as placeholder. As @scsskid said, passing the computed value via v-html renders it as HTML.
It works this way just because all the nested block fields I have contain a required text field. Otherwise I guess you would have to make a more thorough check for what placeholder value to use for each nested blocks field type.
Alternatively, I discovered that I could also do a much simpler preview without computed value if I just output whatever the first nested field contains, like this:
Does the job if you only need the content. As soon as you want to make it look good you need to check for the element’s type and write a lot of stuff. Something like content.elements.toBlocks whould be great!!