Copied to clipboard

Flag this post as spam?

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


  • Linx 98 posts 258 karma points
    Oct 19, 2023 @ 11:37
    Linx
    0

    Get Property value from page/Doc type

    Hi guys

    Been going over a few tutorials on Umbraco 10 and i have a few pages created as below (Home has a Home document type and all Child pages have Child Doc type)

    Home
    ==Child 1
    ==Child 2
    ==Child 3
    ==Child 4

    On the homepage i would like to display a list of Children with their page link and any additional properties i have.

    I created a new controller inheriting from SurfaceController but this doesnt seem to work - my assumption is this Controller is only for Submitting forms?

    I then decided to use UmbracoApiController but that looks to be useful for creating packages.

    Could anyone help me get back on track with this please

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Oct 19, 2023 @ 11:53
    Huw Reddick
    1

    Hi Linx,

    To get the cild pages on your homepage you can just do

    var children = Model.Children();
    

    Which returns an IEnumarable<IPublishedContent>

  • Linx 98 posts 258 karma points
    Oct 19, 2023 @ 13:07
    Linx
    0

    Hi Huw

    That partially works but i cant get access to any of the properties i created.

    It seems to be returning IPublishedContent like you rightly mentioned but how would i go about converting it to a Child Doc type?

    I could do it the old way by looking for the property name (something like .GetProperty("name") but i was hoping for a strongly typed approach (I am using models builder).

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Oct 19, 2023 @ 13:43
    Huw Reddick
    100

    If you are using ModelsBuilder, you should be able to cast the results

    foreach (IPublishedContent childpage in Model.Children())
    {
        var strongchild = (ChildDocType)childpage;
        var tagtest = strongchild.MyTags;
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft