Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • John Churchley 27 posts 172 karma points
    May 28, 2013 @ 20:29
    John Churchley
    0

    Multi-Node Tree Picker in Partial View

    Trying to attempt to display content in a partial view though the use of the Multi-NodTree Picker (Alias homePreviewColumns)

    Issue lies in NodeById is inherted through umbraco.MacroEngines.DynamicNodeContext and as I'm in MVC mode I need to inherit from Umbraco.Web.Mvc.UmbracoTemplatePage. Please correct me if I'm wrong?

    Does anyone know of a work around?

    @using umbraco.MacroEngines
    @using umbraco;
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        if (CurrentPage.HasProperty("homePreviewColumns"))
        {
            int[] nodeList = uQuery.GetXmlIds(CurrentPage.homePreviewColumns.ToXml());
            foreach (int preview in nodeList)
            {
                var node = Model.NodeById(preview);
                <p>@node.name</p>
            }
        }
    
    }
  • John Churchley 27 posts 172 karma points
    May 29, 2013 @ 00:44
    John Churchley
    100

    Solved!

    My solution was to create an instance of DynamicNode but could of used umbraco.NoteFactory

    @{
        int[] nodeList = uQuery.GetXmlIds(CurrentPage.homePreviewColumns.ToXml());
            foreach (int preview in nodeList)
            {
            var node = new DynamicNode(preview);
    //var node = new umbraco.NodeFactory.Node(preview);  Alternative
    @node.GetProperty("pageTitle").Value
    @node.GetPropertyValue("pageContent")}
  • Mark 49 posts 130 karma points
    May 29, 2013 @ 02:23
    Mark
    0

    I like to work with IPublishedContent so have an extension method like so (also store tree picker as csv not xml).

     

        public static IEnumerable<IPublishedContent> GetContentList(this IPublishedContent page, string alias)
        {
            return cache.Get<IEnumerable<IPublishedContent>>("GetContentList[" + page.Id + "," + alias + "]", () =>
            {
                if (!page.HasValue(alias)) return new List<IPublishedContent>();
                var ids = page.GetPropertyValue<string>(alias)
                    .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(x => int.Parse(x));
                var helper = new UmbracoHelper(UmbracoContext.Current);
                return helper.TypedContent(ids).Where(x => x != null);
            }, file: UMBRACO_CONFIG);
        }
    

     

    then you can just use it like so

    Model.Content.GetContentList("homePreviewColumns")

    You could also extend UmbracoHelper for a similar result.

    Still need to investigate performance/details of TypedContent though and check whether the caching actually helps...

     


     

  • John Churchley 27 posts 172 karma points
    Jun 05, 2013 @ 12:03
    John Churchley
    0

    Thanks Mark!

Please Sign in or register to post replies

Write your reply to:

Draft