Copied to clipboard

Flag this post as spam?

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


  • P.J. Melies 18 posts 108 karma points
    Mar 04, 2021 @ 19:45
    P.J. Melies
    0

    Custom Property on Articulate Document Type

    We have added some custom properties by way of a Composition to the Articulate Document Type. enter image description here

    We have created content based on the Articulate Document Type and have set the custom property values appropriately. enter image description here enter image description here

    However, we can't access any of those custom properties from the Model in the Razor code. Stepping through the code in debug mode I noticed that the Model.Content.DocumentTypeAlias="articulateArchive" when I expected it to be Articulate. enter image description here

    Is this expected behavior? If it is then does this mean I would need to add those custom properties to the Articulate Archive Document Type instead of the Articulate Document Type? If I do that I'll lose the ability to set those properties from the Content node in the back office won't I?

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Mar 06, 2021 @ 11:41
    Marc Goodson
    100

    Hi P.J.

    The explanation for what you are experiencing lies in the implementation of Articulate, if you look in the source control, there is an ArticulateController that hijacks all requests to the 'Articulate' Doc Type (eg your News Page):

    https://github.com/Shazwazza/Articulate/blob/af811609762b1fb5574eb1c21baf4d220bf8c8f9/src/Articulate/Controllers/ArticulateController.cs#L45

    When the 'RenderView' method is called:

      var listNodes = model.Content.ChildrenOfType(ArticulateConstants.ArticulateArchiveContentTypeAlias).ToArray();
                if (listNodes.Length == 0)
                {
                    throw new InvalidOperationException("An ArticulateArchive document must exist under the root Articulate document");
                }
    
                var master = new MasterModel(model.Content);
    
                var count = Umbraco.GetPostCount(listNodes.Select(x => x.Id).ToArray());
    
                var posts = Umbraco.GetRecentPosts(master, p ?? 1, master.PageSize);
    
                return GetPagedListView(master, listNodes[0], posts, count, p);
    

    You can see 'MasterModel' is created from the current IPublishedContent eg the Articulate Node, but then the children of this node are looped through, looking for an ArticulateArchive. This is because the default behaviour of requests to the Articulate 'blog homepage' is to list out blog posts.

    Because this listing happens in lots of places in Articulate there is a GetPagedListView helper, who takes the context of the page and renders the list of Blog Posts - but if you look when it is created in this controller, yes the master model is passed, but it's the 'first' articulatearchive listNodes[0] that is passed through as the context of the page to make the listing:

    protected ActionResult GetPagedListView(IMasterModel masterModel, IPublishedContent pageNode, IEnumerable<IPublishedContent> listItems, long totalPosts, int? p)
    

    https://github.com/Shazwazza/Articulate/blob/dabfbd57cd2f45989f85d87fe12d546e4ee2faf2/src/Articulate/Controllers/ListControllerBase.cs#L31

    So the DocumentType of the 'Model' is now the 'articulateArchive' document type and NOT the 'articulate' one...

    ... so the behaviour, I think, is 'by design'.

    There are probably options for extending and overriding these base elements, but pragmatically you should be able to access the new properties on the Articulate DocType recursively, eg

    Model.Content.GetPropertyValue<string>("aliasOfProperty",true);
    

    passing 'true' will look up the Umbraco content tree for the first instance of the property...

    Anyway, hope that explains what's going on, and you can use this to find a good workaround to display your properties.

    regards

    Mar

  • P.J. Melies 18 posts 108 karma points
    Mar 16, 2021 @ 16:04
    P.J. Melies
    0

    Thanks Marc for the explanation and the links to the source code. I understand now and your proposed solution is exactly what I was looking for.

Please Sign in or register to post replies

Write your reply to:

Draft