question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refurbish IPublishedContent (was: not created nodes are returned by children property)

See original GitHub issue

If 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:closed
  • Created 4 years ago
  • Comments:33 (32 by maintainers)

github_iconTop GitHub Comments

3reactions
zpqrtbnkcommented, Apr 24, 2019

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 and IPublishedPropertyType, and IPublishedElement and IPublishedContent use them exclusively (vs PublishedContentType and PublishedPropertyType), thus making them easier to mock and test.

The following IPublishedContent members change:

  • Name: content.Name is gone, content.GetCulture(...).Name is gone, the proper way to get a name is content.Name(string culture = null)
  • UrlSegment: content.UrlSegment is gone, content.GetCulture(...).UrlSegment is gone, the proper way to get a Url segment is content.UrlSegment(string culture = null)
  • ItemType: content.ItemType is gone, the proper way to get the item type is content.ContentType.ItemType
  • Culture: content.Cultures now returns a collection of string representing the available cultures, and content.GetCulture(...) is gone, the proper way to get the culture date is content.CultureDate(string culture = null)
  • Parent: content.Parent is gone, the proper way to get the parent is content.Parent()
  • Children: content.Children is gone, the proper way to get the children is content.Children(string culture = null) and it always filters children according to culture
  • Url: content.Url, .GetUrl(...), .Url(), .UrlAbsolute() are all gone, the proper way to get the Url is content.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 with UrlMode.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 as content.GetCultureFromDomains().

Remaining Work

While we are breaking IPublishedContent we should deal with #3667 (move Children() and Parent() to extension methods - not sure we really want this)

Then, need to cleanup Url getters on UmbracoContext

2reactions
zpqrtbnkcommented, Apr 23, 2019

Plans is indeed to ship with 8.1.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found