PiranhaCMS / piranha.core

Piranha CMS is the friendly editor-focused CMS for .NET that can be used both as an integrated CMS or as a headless API.

Home Page:http://piranhacms.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fetching custom regions via the api

liamkavfc opened this issue · comments

I want to use Piranha in headless mode so have been playing with the api to see its capabilities, but when I added a custom region to my custom page type, the api threw an Exception as it didnt know how to handle my custom region. Is this just not available to do? Or is the something more I have to do?

[PageType]
public class MyPage : Page<MyPage>
{
   [Region]
    public MyBody HtmlBody { get; set; }
}

public class MyBody
{
    [Field]
    public HtmlField Body { get; set; }
}

Hi there! The problem here is that the serialization/deserialization does not support class regions with a single property (see https://piranhacms.org/docs/master/content/regions for reference). If your region will only contain a single field, the correct way is to add that field directly as the region:

public class MyPage : Page<MyPage>
{
   [Region]
   public HtmlField HtmlBody { get; set; }
}

Best regards