首页 > 解决方案 > How to set a CheckBoxField initially checked when adding a new block in manager in Piranha CMS

问题描述

I'm creating a custom block with some ChekBoxFields in Piranha CMS. When a user adds this block in a page in the manager, I want to set some of the Checkbox as already checked.

I am new to C# and Piranha and I am not able to understand how to do it, nor I could find a clue in the docs or searching.

Here is what I tryed first:

[Field(Title = "Show controls")]
public CheckBoxField EnableControls { get; set; } = new CheckBoxField { Value = true};

And then:

[Field(Title = "Show controls")]
public CheckBoxField EnableControls { get; set; } = true;

Then I tryed to set the value in the constructor:

public MyBlock()
{
    EnableControls = true;
}

In all cases the checkbox starts unchecked.

Can anyone help me or point me to some resource about it?

Thank you.

标签: piranha-cms

解决方案


推荐阅读