AI OnAI Off
Hi Johnv,
You can use Content delivery api api for this-
https://world.episerver.com/documentation/developer-guides/content-delivery-api/
Implementation example-
https://mmols.io/getting-started-with-the-episerver-content-delivery-api/
https://dev.solita.fi/episerver/2019/11/12/customizing-episerver-content-delivery-api.html
Maybe this feels hacky, I do not know. Guess it should work.
@model DxcAlloy.Models.Blocks.ItemBlock
@if (PageEditing.PageIsInEditMode)
{
@Html.PropertyFor(x => x.name)
}
else
{
@Html.Raw("{\"id\":" + Model.id + ", \"name\":\"" + Model.name + "\"}")
}
If you create a simple new block, with a few properties, we want to show just a single line of text in the editor, but for the website, we want to generate JSON.
Currently, we havce a single view in /Views/Shared/Blocks/ItemBlock.cshtml:
However, for the editor view, we just want the name, such as:
Is there a way to have different views for the editor and for the actual web page?
Interestingly, even with the above very simple view, its quite different from website to editor. Website shows it like this:
{ "id":123 , "name": "item name" }
But editor shows it like this:
{ "id":
123
, "name": "
item name
" }