Refurbish IPublishedContent (was: not created nodes are returned by children property)
See original GitHub issueIf you add a language to a site with childnodes the childnodes are visible as “not created” nodes.
If you add content to the rootnode and publish it and do @Model.Children
in a template you get all the childnodes including the “not created” children. If you do @Model.Children()
you only get the published children.
Reproduction
Create a documenttype and create a rootnode with 4 children. Add a new language Publish the rootnode of the new language and only one of the children
In the rootnode template paste the following code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test template</title>
</head>
<body>
@{
IEnumerable<IPublishedContent> brokenChildren = Model.Children;
IEnumerable<IPublishedContent> normalChildren = Model.Children();
}
<h4>Children property</h4>
<ul>
@foreach (IPublishedContent child in brokenChildren)
{
<li>childname = @child.Name</li>
}
</ul>
<h4>Children method</h4>
<ul>
@foreach (IPublishedContent child in normalChildren)
{
<li>childname = @child.Name</li>
}
</ul>
</body>
</html>
The first list will return 4 list items where only one has a actual name. The second list will return only the one published node.
I expect the results to be the same as in Umbraco v7
Issue Analytics
- State:
- Created 4 years ago
- Comments:33 (32 by maintainers)
Top Results From Across the Web
get children of children - Using Umbraco And Getting Started
I want this side nav to be dynamic so it can render the children of children no matter what node is selected.
Read more >Common Pitfalls & Anti-Patterns - Umbraco CMS
Information on common Pitfalls and Anti-Patterns in Umbraco. ... return Ok();. } ... Creating new nodes for form submissions - this should be...
Read more >Why do I keep seeing Umbraco.Web.PublishedModels and ...
These methods return IEnumerable<IPublishedContent> . Children() // this is the same as using the Children property on the content item.
Read more >Node: childNodes property - Web APIs - MDN Web Docs
The read-only childNodes property of the Node interface returns a live NodeList of child nodes of the given element where the first child...
Read more >Node — Godot Engine (stable) documentation in English
Note: The script property is part of the Object class, not Node. It isn't exposed like most properties but does have a setter...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
PR is #5312, up for testing and reviews and comments - we want this to be consistent!
Contains Breaking Changes!
Two new interfaces have been introduced:
IPublishedContentType
andIPublishedPropertyType
, andIPublishedElement
andIPublishedContent
use them exclusively (vsPublishedContentType
andPublishedPropertyType
), thus making them easier to mock and test.The following
IPublishedContent
members change:content.Name
is gone,content.GetCulture(...).Name
is gone, the proper way to get a name iscontent.Name(string culture = null)
content.UrlSegment
is gone,content.GetCulture(...).UrlSegment
is gone, the proper way to get a Url segment iscontent.UrlSegment(string culture = null)
content.ItemType
is gone, the proper way to get the item type iscontent.ContentType.ItemType
content.Cultures
now returns a collection ofstring
representing the available cultures, andcontent.GetCulture(...)
is gone, the proper way to get the culture date iscontent.CultureDate(string culture = null)
content.Parent
is gone, the proper way to get the parent iscontent.Parent()
content.Children
is gone, the proper way to get the children iscontent.Children(string culture = null)
and it always filters children according to culturecontent.Url
,.GetUrl(...)
,.Url()
,.UrlAbsolute()
are all gone, the proper way to get the Url iscontent.Url(string culture = null, UrlMode mode = UrlMode.Auto)
which produces a relative-or-absolute Url depending on what’s “best”, but can be forced to produce absolute Urls withUrlMode.Absolute
Finally, v7 had
content.GetCulture()
that was deriving a culture from domains. Somehow that was lost when working on v8 (issue #5269). It has been re-instated ascontent.GetCultureFromDomains()
.Remaining Work
While we are breaking
IPublishedContent
we should deal with #3667 (moveChildren()
andParent()
to extension methods - not sure we really want this)Then, need to cleanup Url getters on
UmbracoContext
Plans is indeed to ship with 8.1.