How to add a field to a Content-Type in OrchardCoreCMS?

78 views Asked by At

Using code, I am trying to create a "Widget" Content-Type called FeaturedProperties with an editable field called MaxVisibleField. I want the MaxVisibleField field to show up under the Fields section when editing the content-type.

I used migration to create a new Contact-Part called MaxPropertiesToShow and created a field called MaxVisibleField for the MaxPropertiesToShow part.

I am expecting the MaxVisibleField field to show up when the “Widget” is edited in the admin panel. When I edit the FeaturedProperties content-type, I see no fields listed. However, I do see the part.

What else do I need to do to make my field MaxVisibleField show up when my Widget is being edited?

Here is my migration code

public int Create()
{
    _contentDefinitionManager.AlterPartDefinition("MaxPropertiesToShow", (part) =>
    {
        part.WithField("MaxVisibleField", c =>
        {
            c.OfType(nameof(NumericField))
            .WithDisplayName("Max Properties To Show")
            .WithDescription("The app with display up to this many properties")
            .WithSettings(new NumericFieldSettings()
            {
                Required = true,
                Maximum = 50,
                DefaultValue = "8",
            });
        });
    });

    _contentDefinitionManager.AlterTypeDefinition("FeaturedProperties", (type) =>
    {
        type.Stereotype("Widget")
        .Creatable(false)
        .Listable(false)
        .Versionable(false)
        .WithPart(nameof(FeaturedPropertyPart));
    });

    return 1;
}

Here is a screenshot of what I am seeing

enter image description here

Also, in the Widget-FeaturedProperties.cshtml view, how can I render the title in a place I want it to show up instead of the standard position the app displays it in?

0

There are 0 answers