Copied to clipboard

Flag this post as spam?

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


  • Dibs 202 posts 991 karma points
    Jun 28, 2017 @ 08:26
    Dibs
    0

    Render DocTypes on a general branch page

    Hi Umbraco Team

    I have created a DocType 'Branch' that will be used as a standard branch page multiple times on a site, each branch page will have child pages of a specific DocType i.e. News, Event, Staff Profile.

    How would you allow the general branch page to render it child pages by DocType ?

    thanks Dibs

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Jun 28, 2017 @ 09:40
    Alex Skrypnyk
    0

    Hi Dibs

    Did you mean to render it via Razor? Something like that:

    @foreach(var child in Model.Content.Children.Where(c => c.DocumentTypeAlias.Equals("GeneralInformation")))
    {
        <a href="@child.Url">@child.Name</a>
    }
    
  • Dibs 202 posts 991 karma points
    Jun 28, 2017 @ 11:52
    Dibs
    0

    Hi Alex

    Thanks for your reply, using your code would only render GeneralInformation DocType if they were child pages of the branch page.

    I have two branch pages of the same DocType using the same template. One branch page has child pages of one specific DocType (news )and the other branch page as another specific DocType (event).

    I would like each branch page to render only each other child pages

    Thanks Dibs

  • siko 24 posts 77 karma points
    Jul 05, 2017 @ 03:50
    siko
    0

    Hi Dibs,

    I created a 'Composable Page' Document Type with children of several types of Document Types (via persmissions in Document Type editor).

    Regardless of the Document Type of the child(eren) of your Branch page, you can:

     foreach (var child in Model.Content.Children())
    {
        @MvcHtmlString.Create(library.RenderTemplate(child.Id))
    }
    

    I realize this is against recommendations (i.e. using the RenderTemplate function, as per RenderTemplate warning) and perhaps should be solved by rendering the partial view directly?

    I hope this steers you in the right direction anyway!

    Regards,

    Sijmen

  • siko 24 posts 77 karma points
    Jul 05, 2017 @ 04:17
    siko
    0

    Additional:

    You could introduce a property on your Branch node to specify the type of children. This value you could use to filter the type of items you want to render.

    Now, about to use RenderTemplate or not, consider the usage of:

    @foreach(var child in Model.Content.Children())
    {
        @Html.Partial("MyPartialName", child)
    }
    

    HTH

Please Sign in or register to post replies

Write your reply to:

Draft