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?
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.
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.
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.
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?
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
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.
Hi there,
CurrentPage
is of the typeDynamicPublishedContent
and notIPublishedContent
. Using dynamics is not recommended, you should useIPublishedContent
instead.What's the
@inherits
statement at the top of your template?If it's
UmbracoTemplatePage
, you can access the current page model (IPublishedContent) fromModel.Content
: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:
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
Hi Rune,
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.
I have used
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.
is working on a reply...