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?
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.
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.
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
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
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.
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.
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.
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?
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...
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
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.
Hi Harry
Do you mean the template 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
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:
and in your Partial View you would define the model as
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:
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 :-)
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
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.
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.
is working on a reply...