type .WithPart(" /> type .WithPart(" /> type .WithPart("/>

How can I set the custom path of an AutoroutePart programmatically in a migration in Orchard?

85 Views Asked by At

In my Migrations.cs file I'm attaching an AutoroutePart to a Content Item.

ContentDefinitionManager.AlterTypeDefinition("Faq", type => type
    .WithPart("AutoroutePart")    
);

How can I tell the AutoroutePart to use some arbitrary string + the Content Item's slug as the custom path? I know I can change the settings of fields using .WithSetting("FieldSettings.Setting","Value") but this doesn't seem to be an option for Parts. I also wouldn't know how to refer to the SlugToken in code.

1

There are 1 best solutions below

1
Hazza On BEST ANSWER

Should be possible

ContentDefinitionManager.AlterTypeDefinition("Faq", type => type
.WithPart("AutoroutePart", part => part
    .WithSetting("AutorouteSettings.AllowCustomPattern", "True")
    .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
    .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-faq\"}]")
    .WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))));