Copied to clipboard

Flag this post as spam?

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


  • Abhishek 15 posts 85 karma points
    Sep 25, 2018 @ 10:12
    Abhishek
    0

    How to pull only the published nodes to the web page

    Hi Right now my web page is showing all the nodes, which are not published as well How to restrict the unpublished nodes? And could you please explain the IPublishedContent functionality?

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Sep 25, 2018 @ 11:18
    Nik
    0

    Hi Hemanth,

    How are you getting your nodes? The normal Umbraco behaviour when following the patterns would mean that the front end of the site only gets published content so it seems odd that it's not.

    Thanks

    Nik

  • Abhishek 15 posts 85 karma points
    Sep 25, 2018 @ 13:02
    Abhishek
    0
    LB lb = (LB)ViewData["lb"];
    IPublishedContent currentPage = CurrentPage;
    IPublishedContent dealer = currentPage.Parent;
    IEnumerable<IPublishedContent> values = currentPage.Descendants().Where(x => x.DocumentTypeAlias == "genericValues");
    

    I am using IPublishedContent in my view this way. This is a parent node and it has child nodes to it.

    So at the CurrentPage. I am getting all the child nodes including UnPublished ones.

    Could you please help me how to use IPublishedContent, so that only the published ones will show-up in view

    And there is no check at the IPublishedcontent level, to check whether it is published or not like, IsPublished. it has IsDraft check, but it is not useful in my case.

  • Rune Hem Strand 147 posts 911 karma points hq c-trib
    Sep 25, 2018 @ 14:16
    Rune Hem Strand
    0

    Hi there,

    CurrentPage is of the type DynamicPublishedContent and not IPublishedContent. Using dynamics is not recommended, you should use IPublishedContent instead.

    What's the @inherits statement at the top of your template?

    If it's UmbracoTemplatePage, you can access the current page model (IPublishedContent) from Model.Content:

    var dealer = Model.Content.Parent;
    var values = dealer.Children<GenericValues>();
    

    The above is assuming you're using modelsbuilder (where GenericValues is created automatically based on the document type alias), if this is not the case you can do something like:

    var dealer = Model.Content.Parent;
    var values = dealer.Children().Where(x => x.DocumentTypeAlias == "genericValues");
    

    I've used children on purpose here, so if you have got genericValue nodes deeper in the tree that won't work. Just be extremely careful .Descendants as it retrieves everything, which can be really expensive, depending on how many nodes it is returning.

    A couple of links that might be of interest:
    Dynamics vs strongly typed
    IPublishedContent
    Working with models builder

    Hope that helps :)

    All the best
    Rune

  • Abhishek 15 posts 85 karma points
    Sep 25, 2018 @ 15:50
    Abhishek
    0

    Hi Rune,

    var dealer = Model.Content.Parent;
    

    Is hitting the Parent page. I have child nodes in About Us and the view is for about us, instead of hitting about us node, it is hitting global.

    The flow is:

    Global-> About US-> Child nodes

    At dealer I have to get About Us node instead of Global.

  • Abhishek 15 posts 85 karma points
    Sep 25, 2018 @ 16:14
    Abhishek
    0

    I have used

    var content = dealer.Children.Where(x => x.DocumentTypeAlias == "genericAboutUs").FirstOrDefault();
    

    Now I am able to get the about us child nodes.

    But the issue still persists. The unpublished nodes are still showing up in the view.

Please Sign in or register to post replies

Write your reply to:

Draft