Search the FirstSpirit Knowledge Base
Hello Community,
I have a CaaS architecture, and the template has a html and CaaS code that is in JSON first spirit syntax.
I need to read that json file, convert it the html, and afterwards I will create input components that correspond to the given content (e.g. images, text, headlines, etc.).
Here is the code example of the CaaS :
$CMS_TRIM(level:4)$
$CMS_SET(set_JSON_use_stack_old,set_JSON_use_stack)$
$CMS_SET(set_JSON_use_stack, true)$
$CMS_SET(set_JSON, {:})$
$CMS_SET(void, set_JSON.put("className", "ucp-ekomi-widget"))$
$CMS_SET(void, set_JSON.put("key", "01_11b"))$
$CMS_SET(void, set_JSON.put("element", {:}))$
$CMS_IF(!#global.page.store.isRelease())$
$CMS_SET(void, set_JSON.get("element").put("previewId", previewId().toString()))$
$CMS_END_IF$
$CMS_SET(void, set_JSON.get("element").put("sectionId", #global.section.id.toString()))$
$CMS_SET(void, set_JSON.get("element").put("ekomiId", if(!st_ekomi_id.isEmpty(), st_ekomi_id, "")))$
$CMS_SET(set_JSON_use_stack, set_JSON_use_stack_old)$
$CMS_IF(isSet(set_JSON_use_stack) && set_JSON_use_stack)$
$CMS_SET(void, set_JSON_stack.add(set_JSON_stack.size(), set_JSON))$
$CMS_ELSE$
$CMS_VALUE(set_JSON.toJSON)$
$CMS_END_IF$
$CMS_END_TRIM$
And this is corresponding html code in the same template :
<div class="ekomi-wrapper grey-background" $CMS_VALUE(editorId())$ id="$CMS_VALUE(#global.section.id)$">
$CMS_IF(!st_ekomi_id.isEmpty())$
<div id="eKomiWidget_default" data-cert="$CMS_VALUE(st_ekomi_id,default:"")$">
<!-- Content will be loaded here -->
</div>
$CMS_END_IF$
</div>
So my question is how can I read this json file, that queries content from database and then convert the content in to plain html, and afterwards create a corresponding first spirit input components so that content creator can change content.
Kind regards,
Aleksandar
Hi Aleksandar,
I am not sure if I understand your question. I guess you want to know how to add the markup to edit CaaS JSON with the content creator? As far as I know, this is not directly possible with the content creator (but this is what CXT / FragmentCreator is made for, see Documentation).
So, the "normal" workflow for working with the content creator in conjunction with CaaS is that you have a website that has both a HTML and a JSON channel (as you have here). In that case, there are two representations of your data (output channels): one in HTML and one in JSON. You would add the input elements to the HTML representation, which is edited in content creator. Since the underlying data model is only saved once, you'd edit the data for the JSON representation as well.
So, you would add the edit buttons in your HTML representation, and that works more or less the way you already started (see here for more docs). Data that is only available in the JSON representation can be edited in the edit window for the whole page, which you can open via $CMS_VALUE(editorId())$ you already have.
Unsure if that answers your question, though. If not, feel free to comment!
Kind regards,
Lena
Hi Aleksandar,
I am not sure if I understand your question. I guess you want to know how to add the markup to edit CaaS JSON with the content creator? As far as I know, this is not directly possible with the content creator (but this is what CXT / FragmentCreator is made for, see Documentation).
So, the "normal" workflow for working with the content creator in conjunction with CaaS is that you have a website that has both a HTML and a JSON channel (as you have here). In that case, there are two representations of your data (output channels): one in HTML and one in JSON. You would add the input elements to the HTML representation, which is edited in content creator. Since the underlying data model is only saved once, you'd edit the data for the JSON representation as well.
So, you would add the edit buttons in your HTML representation, and that works more or less the way you already started (see here for more docs). Data that is only available in the JSON representation can be edited in the edit window for the whole page, which you can open via $CMS_VALUE(editorId())$ you already have.
Unsure if that answers your question, though. If not, feel free to comment!
Kind regards,
Lena
Hello Lena,
Thank you for your response, but my issue is following :
As you said I currently have HTML and JSON as CaaS.
But I need to have only html, so I need to convert my CaaS that is in JSON format and after migrating those templates, my templates should only have html code, content would be edited from input components and edited in content creator.
I hope I clarified it a bit for you, I'm sorry if I didn't explained it better.
Regards,Aleksandar
Hi Aleksandar,
actually, I don't really get it, sorry . It would help me if you explain to me what you're trying to achieve - so, context and the (maybe non-technical) bigger picture.
Cheers,
Lena
Hello Lena,
Well I need to keep the content of the website that is currently stored in the MongoDB.
Right now the site is using Content as a Service, and my templates contains both html and CaaS.
CaaS contains JSON in first spirit syntax, and that content after it is queried from database is loaded in html.
I need to keep the content, remove the CaaS and only have html.
King regards,
Aleksandar
So I should achieve following:
Only keep html templates, remove the CaaS and find a way to read that JSON data so I can add the content, keep it, and use only html template, and not html and CaaS which is now the case
Hi Aleksandar,
thanks for the further explanation. We are still not 100% sure about your use case.
You seem to say that you want to retrieve content from the CaaS database in order to somehow use it in your html code?
In most cases, FirstSpirit is the source of the content written to CaaS so the data you need is already there. Unless there is another application persisting additional data to the CaaS database, you would not need to read it back from the CaaS database. Instead, you should be able to access it directly inside FirstSpirit.
Please elaborate further on your future scenario - sounds like you are planning to get rid of CaaS?
Best regards,
Tanja
Since we did not get any more insight into the problem, we are closing this thread.