Copied to clipboard

Flag this post as spam?

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


  • Harry Spyrou 212 posts 604 karma points
    Dec 15, 2017 @ 18:02
    Harry Spyrou
    0

    Get Document Type by Alias (or whatever) in Nested Content -Stuck

    So, I've been trying to render another document type that has a template within my homepage using nested content.

    "custfeedback2" is the collection that has the properties I want to access.

        @inherits Umbraco.Web.Mvc.UmbracoViewPage
    
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "MasterPage.cshtml";
    }
    @Html.Partial("_HomePageHeroBlock")
    
    
        @foreach (var item in Model.GetPropertyValue<IEnumerable<IPublishedContent>>("custFeedback2"))
    
        {
            @Umbraco.TypedContent(item.DocumentTypeId);
        }
    

    If I try @Umbraco.TypedContent(item.Id); then I get (0) and it doesn't work. If I try to get it with something like @RenderPage(item.Url) it returns #. Only DocumentTypeId returns the actual Id. My question is, how can I render the page on my homepage?

    I need it this way (as a looped item). It may be a silly question but I'm stuck here the whole day. Can anyone help?

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Dec 16, 2017 @ 09:53
    Marc Goodson
    0

    Hi Harry

    If I'm understanding correctly then custFeedback2 is your Nested Content property?

    In which case, inside your loop, the item variable represents each nested item in the for of IPublishedContent and so you should be able to do...

    <dl>
        @foreach (var item in Model.GetPropertyValue<IEnumerable<IPublishedContent>>("custFeedback2"))
    
            {
    <dt>Name:</dt>
    <dd>@item.Name</dd>
    <dt>Get a particular property on the nested item:</dt>
    <dd>@item.GetPropertyValue("aliasOfProperty")<dd>           
            }
    </dl>
    

    So you can read the properties of the nested item and write them out on the page, but because the nested item isn't published as it's own node in the Umbraco content tree, it won't have an Id or a Url...

    If each nested item needs it's own url, then you probably wouldn't use nested content, you'd probably create child node/pages underneath this content item.

    There's a better explanation on this page. https://our.umbraco.org/documentation/getting-started/backoffice/Property-Editors/Built-in-Property-Editors/Nested-Content

    regards

    Marc

  • Harry Spyrou 212 posts 604 karma points
    Dec 16, 2017 @ 11:18
    Harry Spyrou
    0

    Hi Marc

    Yes you're right about custFeedback2

    Thanks for your answer. In this case, I don't want to render the properties immediately one by one. I want to render the whole template that my document type is looking in. The one that nested content asks you to fill in when you're picking the document types available for use.

    The problem is that I want them created one by one as blocks of content depending on the order of nested content. So:

    Let's say cystimer feedback is Container A.

    I want the client to be able to do this by dragging and dropping:

    Container A Container B Container C

    Container B Container C Container A

    If I do it your way then I will have 3 loops one for each container but no matter the order the client wants to position it Container A will always position first because the loop executes first. Am I wrong?

    Edit: Let me say that the 3 containers contain completely different code. I'm not creating identicall document types or blocks of identical code.

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Dec 16, 2017 @ 17:15
    Marc Goodson
    101

    Hi Harry

    Do you mean the template here:

    enter image description here

    if so... this isn't the template that renders the item in a nested content list!

    This is the template (an angularJs expression) that controls the label format that the editor will see, when they are working with nested content in the backoffice, instead of Item1, Item2, Item3 etc

    enter image description here

    if that makes sense?

    What I think you are looking to do in your loop is render a partial view, passing the full IPublishedContent item for each nested item eg:

    @foreach (var item in Model.GetPropertyValue<IEnumerable<IPublishedContent>>("custFeedback2"))
    
        {
            @Html.Partial("MyPartialViewForNestedItems", item)
        }
    

    and in your Partial View you would define the model as

        @inherits UmbracoViewPage<IPublishedContent>
    
    <h1>@Model.Name</h1>
    <div>@Model.GetPropertyValue("bodyText")</div>
    

    this would then be your template for writing out the properties for the nested items eg

    If each type of nested item is a different document type, then you could use the document type alias to call a different partial view in your loop eg:

     @foreach (var item in Model.GetPropertyValue<IEnumerable<IPublishedContent>>("custFeedback2"))    
            {
    var partialViewName = "NestedCustFeedBack_" + item.DocumentTypeAlias;
                @Html.Partial(partialViewName, item)
            }
    

    This would enable you to have a different partial view (template) for each type of nested content to control how the different types are rendered in a single loop.

    or at least that's what I think you are after :-)

  • Harry Spyrou 212 posts 604 karma points
    Dec 16, 2017 @ 18:50
    Harry Spyrou
    0

    Hi Marc,

    So I tested what you told me to do, and yes it works as intended, but it doesn't solve the original problem that I had, which is having the client to be able to move things up and down (not the content inside the container/collection, but move collections up and down).

    If I, for example have a

        @foreach (var item in Model.GetPropertyValue<IEnumerable<IPublishedContent>>("collectionWithaSpecificPartialView"))
    
            {
                @Html.Partial("MyPartialViewForNestedItems", item)
            }
    @foreach (var item in Model.GetPropertyValue<IEnumerable<IPublishedContent>>("collectionWithAnotherPartialView"))
    
            {
                @Html.Partial("MyPartialViewForNestedItems2", item)
            }
    

    Then whenever I try to create something, the "collectionWithAnotherPartialView" will always render second no matter what. What I originally wanted to do is let the collections get rendered in whichever order the client decides they want to. Not one collection. That's why I initially wanted to render by document type alias since each document type has its own template.

    Which I still don't know if it's possible.

  • Harry Spyrou 212 posts 604 karma points
    Dec 16, 2017 @ 17:18
    Harry Spyrou
    0

    I think that's what I'm after. I'll test it and get back to you. Thanks a lot for the time and the replies.

Please Sign in or register to post replies

Write your reply to:

Draft