AgentSkillsCN

orchardcore.content-types

为 Orchard Core 创建、管理并配置内容类型的技能。涵盖内容部分定义、内容字段定义、典型模板,以及内容类型索引编制。

SKILL.md
--- frontmatter
name: orchardcore.content-types
description: Skill for creating, managing, and configuring Orchard Core Content Types. Covers content part definitions, content field definitions, stereotypes, and content type indexing.

Orchard Core Content Types - Prompt Templates

Create a Content Type

You are an Orchard Core expert. Generate code and configuration for creating a content type.

Guidelines

  • Content type technical names must be PascalCase with no spaces.
  • Always include a TitlePart unless the content type uses a custom title strategy.
  • Add AutoroutePart for routable content types with a URL pattern.
  • Use CommonPart conventions (owner, created/modified dates) where appropriate.
  • Attach ListPart if the content type should act as a container.
  • Use content part and field settings to configure editors and display modes.

Migration Pattern

csharp
public sealed class Migrations : DataMigration
{
    public int Create()
    {
        _contentDefinitionManager.AlterTypeDefinition("{{ContentTypeName}}", type => type
            .DisplayedAs("{{DisplayName}}")
            .Creatable()
            .Listable()
            .Draftable()
            .Versionable()
            .WithPart("TitlePart", part => part
                .WithPosition("0")
            )
            .WithPart("AutoroutePart", part => part
                .WithPosition("1")
                .WithSettings(new AutoroutePartSettings
                {
                    AllowCustomPath = true,
                    Pattern = "{{ slug }}"
                })
            )
        );

        return 1;
    }
}

Content Field Configuration

When adding fields to a content part:

csharp
_contentDefinitionManager.AlterPartDefinition("{{PartName}}", part => part
    .WithField("{{FieldName}}", field => field
        .OfType("{{FieldType}}")
        .WithDisplayName("{{FieldDisplayName}}")
        .WithPosition("{{Position}}")
    )
);

Common field types include:

  • TextField - simple text input
  • HtmlField - rich HTML editor
  • NumericField - numeric values
  • BooleanField - true/false
  • DateField / DateTimeField - date pickers
  • ContentPickerField - reference to other content items
  • MediaField - media library attachment
  • LinkField - URL with optional text
  • TaxonomyField - taxonomy term selection