1 2 3 4 5 6 7 8 | DEFINE MODEL: [UIHint(UIHint.Image)]
[Display(Name = "MainLogo",
Description = "Main Sites Logo",
GroupName = SystemTabNames.Content)]
public virtual ContentReference MainLogo { get; set; }
GET: var urlHelper = ServiceLocator.Current.GetInstance<UrlHelper>(); var friendlyUrl = urlHelper.ContentUrl(Model.CurrentBlock.MainLogo); |
Tuesday, January 14, 2020
C# - EpiServer - Get Url To a Image
Sunday, January 12, 2020
C#, EPiserver - Get all descending pages of all types
var currentCultureInfo = new CultureInfo("no"); var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); var startPage = contentLoader.GetChildren<StartPage>(ContentReference.RootPage, currentCultureInfo).FirstOrDefault(); ICollection<PageData> listOfPages = new List<PageData>(); ContentReferenceExtensions.GetDescendantsOfType<PageData>(startPage, listOfPages, currentCultureInfo); /// <summary> /// Recursive GetDescendantsOfType /// </summary> /// <typeparam name="T"></typeparam> /// <param name="page"></param> /// <param name="descendants">results</param> /// <param name="language"></param> public static void GetDescendantsOfType<T>(PageData page, ICollection<T> descendants, CultureInfo language) where T : class { var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); var children = contentRepository.GetChildren<PageData>(page.ContentLink, language); foreach (var child in children) { if (child is T) { descendants.Add(child as T); } GetDescendantsOfType(child, descendants, language); } }
C#, EPiserver - Page Type Criteria (200112)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | var currentCultureInfo = new CultureInfo("no"); var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); var startPage = contentLoader.GetChildren<StartPage>(ContentReference.RootPage, currentCultureInfo).FirstOrDefault(); var ptRepo = ServiceLocator.Current.GetInstance<IContentTypeRepository>(); var myPage = ptRepo.Load("StandardPage").ID; PropertyCriteria pageTypeCriteria = new PropertyCriteria(); pageTypeCriteria.Condition = EPiServer.Filters.CompareCondition.Equal; pageTypeCriteria.Name = "PageTypeID"; pageTypeCriteria.Type = PropertyDataType.PageType; pageTypeCriteria.Value = myPage.ToString(); PropertyCriteriaCollection criteriaCollection = new PropertyCriteriaCollection(); criteriaCollection.Add(pageTypeCriteria); DescendantPages = DataFactory.Instance.FindPagesWithCriteria(startPage?.PageLink, criteriaCollection) .Cast<PageData>(); |
Subscribe to:
Posts (Atom)