所以我通过migration.cs文件添加一个页面,这个工作正常。 问题是,如果我运行两次更新,它将添加两次页面。 虽然我知道在舞台/ prod中,情况并非如此。 但是在dev中我们重新运行了几次发布代码以使其全部工作。
无论如何,我想要的是
private readonly IContentManager _contentManager;
// this line is made up
var articleListingPage = _contentManager.GetPages.SingleOrDefault(p => p.Name == "ArticleListingPage");
if (articleListingPage == null)
{
var articlesPage = _contentManager.Create("Page");
articlesPage.As<TitlePart>().Title = "ArticleList";
articlesPage.As<BodyPart>().Text = @"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus mauris magna, varius vel vulputate eget, bibendum id magna.</p>";
articlesPage.As<CommonPart>().Owner = _orchardServices.WorkContext == null ? null : _orchardServices.WorkContext.CurrentUser;
var articlesRoute = articlesPage.As<AutoroutePart>();
articlesRoute.DisplayAlias = _autorouteService.GenerateAlias(articlesRoute);
_autorouteService.PublishAlias(articlesRoute);
var menu = _menuService.GetMenu("Main Menu");
if (menu == null) throw new Exception("Could not get the menu. Please the name of the menu is correct.");
articlesPage.As<MenuPart>().Menu = menu;
articlesPage.As<MenuPart>().MenuText = "Article List YYYY";
articlesPage.As<MenuPart>().MenuPosition = "10";
_contentManager.Publish(articlesPage);
}
有谁知道如何找到网页/内容的集合?
答案 0 :(得分:0)
我明白了。作为其动态,它基于项目中的内容部分。 在此示例中,“TitlePart”被添加到内容类型“Page”
var list = _contentManager.Query(VersionOptions.Published, "Page")
.List().Cast<dynamic>();
var existingPage = list.Any(i => i.TitlePart.Title == "ArticleList");
if (existingPage == false)
{
//add page etc
}