I have a page that needs to load a lot of dynamic content.
This content is stored as a json object (generated by https://editorjs.io/ , example object:
{
"body": {
"time": 1655912890286,
"blocks": [
{
"id": "6el1Ox2NGo",
"data": {
"text": "Heading"
},
"type": "paragraph"
},
{
"id": "LyOvywDEYC",
"data": {
"text": "Paragraph text goes here<br>"
},
"type": "paragraph"
},
{
"id": "sokGcDrI-7",
"data": {
"file": {
"url": "https://dl.smartclasses.app/school/1/reading-page/9/content/parsifal5_2.jpg"
},
"caption": "man at facebook",
"stretched": false,
"withBorder": false,
"withBackground": false
},
"type": "image"
},
{
"id": "OOxO_OLNJx",
"data": {
"text": "There is a lot of content here. This is a paragraph that I am just typing now."
},
"type": "paragraph"
},
{
"id": "JtyXtSS8xK",
"data": {
"text": "And this is another paragraph."
},
"type": "paragraph"
},
{
"id": "D5OMTNppMj",
"data": {
"text": "This is another heading",
"level": 2
},
"type": "header"
},
{
"id": "nR8g6Bhqj2",
"data": {
"text": "‍Smaller heading ",
"level": 3
},
"type": "header"
},
{
"id": "RTu1j7SrkY",
"data": {
"text": "more text<br>"
},
"type": "paragraph"
},
{
"id": "4QLuFaz6Qc",
"data": {
"link": "smartclasses.app",
"text": "Lovely CTA"
},
"type": "AnyButton"
}
],
"version": "2.24.3"
}
}
I load it on the page, but it shows up very slowly. Probably due to the many repeating appconnect formatters.
2022.06.22 17.49 - 4501 - Mantid
This is how I’m parsing it now to show on the page:
(the input of the repeat is the object shown above)
<div dmx-repeat:repeat1="reading_page_get.data.query_reading_page_info.body.blocks">
<div id="conditionalParagraph" is="dmx-if" dmx-bind:condition="type=='paragraph'">
<p>{{data.text}}</p>
</div>
<div id="conditionalH2" is="dmx-if" dmx-bind:condition="type=='header'&&data.level==2">
<h2 class="rp-h2">{{data.text}}</h2>
</div>
<div id="conditionalH3" is="dmx-if" dmx-bind:condition="type=='header'&&data.level==3">
<h3 class="rp-h3">{{data.text}}</h3>
</div>
<div id="conditionalH4" is="dmx-if" dmx-bind:condition="type=='header'&&data.level==4">
<h4 class="rp-h4">{{data.text}}</h4>
</div>
<div id="conditionalImage" is="dmx-if" dmx-bind:condition="type=='image'">
<figure class="figure">
<img dmx-bind:src="{{data.file.url}}" class="figure-img img-fluid rounded" dmx-bind:alt="{{data.caption}}">
<figcaption class="figure-caption" dmx-show="data.caption">{{data.caption}}</figcaption>
</figure>
</div>
<div id="conditionalButton" is="dmx-if" dmx-bind:condition="type=='AnyButton'">
<div class="d-grid col-6 mx-auto">
<a class="btn btn-primary" dmx-bind:href="{{data.link}}">{{data.text}}</a>
</div>
</div>
</div>
This is loading a lot of elements in the DOM as well
There must be a better way to do what I’m doing here. Please tell me!
PS to clarify: for each object I want to check what type it is, then based on that type I want to show certain HTML. So let’s say type=="image"
then I want to load <img...
with the other values in that object.