Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can, when creating a page as part of migrations.cs in a module, tell the Autoroute part to set your created page's alias as the homepage:</p> <pre><code> //create a page page var homepage = _contentManager.Create("Page"); homepage.As&lt;TitlePart&gt;().Title = "My Home"; _contentManager.Publish(homepage); var homePageArp = homepage.As&lt;AutoroutePart&gt;(); homePageArp.DisplayAlias = String.Empty; _autorouteService.PublishAlias(homePageArp); </code></pre> <p>This assumes you're going from a clean instance of Orchard without any prior homepages; if you have an existing homepage, you'll have to regenerate those pages' Aliases as part of your module too. This is how it's done as part of the AutoroutePartHandler in the Orchard.Autoroute project (inside the Publish Alias method):</p> <pre><code> // regenerate the alias for the previous home page var currentHomePages = _orchardServices.ContentManager.Query&lt;AutoroutePart, AutoroutePartRecord&gt;().Where(x =&gt; x.DisplayAlias == "").List(); foreach (var current in currentHomePages) { if (current != null) { current.CustomPattern = String.Empty; // force the regeneration current.DisplayAlias = _autorouteService.Value.GenerateAlias(current); } _autorouteService.Value.PublishAlias(current); } _autorouteService.Value.PublishAlias(part); </code></pre> <hr> <p>If you dig through the driver and handler for the autoroute project, you'll learn a lot about the internals; when you tick that "set as homepage" box in the Admin UI, it sets the Path to "/" and then that gets picked up, triggers the old homepage re-wire, clears the "/" path to String.Empty and then publishes that blank alias, giving you a new homepage.</p> <p>(this is valid as of Orchard 1.6)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload