Skip to content

A Content Type is the blueprint for all content.

内容类型是所有内容的蓝图。

Content Types are created by combining multiple Parts

内容类型是通过组合多个部件创建的

Creating a Content Type from code can be done from your migrations.cs. We'll use the AlterTypeDefintion to create or change a content type definition. The WithPart allows us to add multiple parts.

从代码创建内容类型可以从migrations.cs完成。我们将使用 AlterTypeDefintion 来创建或更改内容类型定义。 * WithPart *允许我们添加多个部分。

Creating a Content Type

创建内容类型

Here we are creating a simple content type with a title

这里我们创建一个带标题的简单内容类型

ContentDefinitionManager.AlterTypeDefinition("Training", builder =>

    builder

        .WithPart("CommonPart")

        .WithPart("TitlePart")

        .Creatable()

        .Draftable());

Creating a more Complex Content Type

创建更复杂的内容类型

In this example we are also changing some of the settings of one of the included parts

在此示例中,我们还更改了其中一个包含部分的一些设置

ContentDefinitionManager.AlterTypeDefinition("Training", builder =>

    builder

        .WithPart("CommonPart")

        .WithPart("TitlePart")

        .WithPart("AutoroutePart", builder => builder

            .WithSetting("AutorouteSettings.AllowCustomPattern", "true")

            .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false")

            .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Title', Pattern: '{Content.Slug}', Description: 'my-blog'}]")

            .WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))

        .WithPart("MenuPart")

        .WithPart("TagsPart")

        .Creatable()

        .Draftable());