I am about to build a block for creating content tables in Episerver.
I would like this block to have a ContentArea
which in turn will contain only blocks of type TableRowBlock
(so that I can have an arbitrary number of rows).
If I create a block type called TableBlock
and another one called TableRowBlock
, they will both be visible when an editor adds a new block.
Since TableRowBlock
only makes sense within a TableBlock
, I would like to hide it so that it is only visible when adding a block to the ContentArea
property of a TableBlock
.
How can I do this?
What you're asking isn't supported out-of-the-box, I'm afraid.
However, you could:
[AllowedContentTypes]
attribute to your ContentArea
property for TableBlock
, and specify the TableRowBlock
type as the allowed type. That way the editor won't have to select block type when clicking "Add new block" in the content area editor.IContentTypeAdvisor
which would suggest TableRowBlock
when TableBlock
is being edited:[ServiceConfiguration(typeof(IContentTypeAdvisor))]
public class ContentTypeAdvisor : IContentTypeAdvisor
{
public IEnumerable<int> GetSuggestions(IContent parent, bool contentFolder, IEnumerable<string> requestedTypes)
{
// Suggest relevant content types
}
}
Full example available here.