November Happy Hour will be moved to Thursday December 5th.

Issues with UIHint/

Vote:
 

I am trying to add a LinkItemCollection in the footer-section of the page. The startpage has a LinkItemCollection that is called "LinkPages". Using edit-hints to connect it for the editors. When viewing the page, the links refuses to come up. Clicking on edit, or adding a new links makes them appear. Saving and viewing the page again and the items will not show up. The links are saved on the startpage LinkItemCollection but will not display.

Models/Pages/StartPage.cs

        [UIHint("LitemItemCollection")]
        [Display(Name = "Link Pages",  GroupName = Global.GroupNames.SiteSettings)]
        public virtual LinkItemCollection LinkPages { get; set; }

DisplayDemplates/LinkItemCollection.cshtml

@using EPiServer.SpecializedProperties
@model LinkItemCollection

    @foreach (var linkItem in Model ?? Enumerable.Empty()) {
  • @Html.PageLink(linkItem)
  • }

IPageViewModel.cs

    public interface IPageViewModel where T : SitePageData
    {
        T CurrentPage { get; }
        LayoutModel Layout { get; set; }
    }

LayoutModel.cs

    public class LayoutModel
    {
        public LinkItemCollection LinkPages { get; set; }
    }
}

PageViewContextFactory.cs

 public class PageViewContextFactory
    {
        private readonly IContentLoader _contentLoader;
        private readonly UrlResolver _urlResolver;
        public PageViewContextFactory(IContentLoader contentLoader, UrlResolver urlResolver)
        {
            _contentLoader = contentLoader;
            _urlResolver = urlResolver;
        }

        public virtual LayoutModel CreateLayoutModel(ContentReference currentContentLink, RequestContext requestContext)
        {
            var startPage = _contentLoader.Get(ContentReference.StartPage);

            return new LayoutModel
            {
                LinkPages = startPage.LinkPages,
            };
        }

        public virtual IContent GetSection(ContentReference contentLink)
        {
            var currentContent = _contentLoader.Get(contentLink);
            if (currentContent.ParentLink != null && currentContent.ParentLink.CompareToIgnoreWorkID(ContentReference.StartPage))
            {
                return currentContent;
            }

            return _contentLoader.GetAncestors(contentLink)
                .OfType()
                .SkipWhile(x => x.ParentLink == null || !x.ParentLink.CompareToIgnoreWorkID(ContentReference.StartPage))
                .FirstOrDefault();
        }
    }

Any ideas?

#89737
Aug 25, 2014 12:13
Vote:
 

If you only want the UI hint to affect the editor and not both the editor and template, you need to speficy this in your UIHint:

[UIHint("something", presentationLayer: PresentationLayer.Edit)]

#89751
Aug 25, 2014 14:33
Vote:
 

The issue is that the visitor can't see the changes. It's just empty.

#89757
Aug 25, 2014 16:16
Vote:
 

Seems to be an issue with the iteration of the data.

hello  
    @foreach (var linkItem in Model ?? Enumerable.Empty()) {
  • @Html.PageLink(linkItem)
  • }


hello always shows up

#89758
Aug 25, 2014 16:19
Vote:
 

Is it not just that the misspelling in the sample UIHint that you posted above is causing this?

"LitemItemCollection"

#89759
Aug 25, 2014 16:20
Vote:
 

That didn't resolve the issue, just a mistake a made when pasting the code.

#89761
Aug 25, 2014 16:29
Vote:
 

Hi

Have you checked in debugger that you have your layoutmodel set and you have any items there when it is passed to template for LinkItemCollection?

We see that you have code to create the layoutmodel but do you actually ever set it for the implementation of your IPageViewModel?

So I would check the code that creates the viewmodel and sets the layoutmodel for it and have breakpoints in code to see that the value is set and if set at what point the linkitemcollection gets "nulled" if that is the case.

#89770
Aug 25, 2014 20:41
Vote:
 

Also, I would strongly recommend to set a UI hint that's different from the value type. I'm not fully sure of the implementation but we resolve views with the value name so adding a hint that's the same as the name of the value seems like begging for trouble.

#89784
Aug 26, 2014 8:31
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.