I have a document type named "home2" and it has various template allowed to used when creating page.how do i get unique list of DocumentType alias..I have written this code..which gets all children of "home2" and returns their doctype alias..but i want distinct list.
Cause I may have two pages of same doctype:
@{var node2 = umbraco.uQuery.GetNodesByType("home2");
if (node2.Any())
{IPublishedContent about = Umbraco.TypedContent(node2.First().Id);
var selection = Umbraco.Content(about.Id);
foreach(var items in selection.Children()){
@items.DocumentTypeAlias()}}}
Having 1 document type with multiple templates can sometimes get a little fragile, you might find it easier if you have a 1 to 1 relationship between Document Types and Templates, giving you more structure within your content - which should make it easier to query nodes / separate concerns.
Example:
Doctype: home => Template: home
Doctype: about => Template: about
For your generic pages, you could perhaps then have an article document type too.
Umbraco has a handy feature that allows you to change a document type by right clicking on the node in the content tree. This is super handy, as it means you can adjust and refine the structure as your are working.
In response to your question, I've included some code below, that shows how to make the content queries in a slightly different and hopefully clearer way.
Example:
@{ var home = Model.Content.AncestorOrSelf("home"); }
@* List all children *@
@foreach (var item in home.Children())
{
<p>@item.Name, @item.DocumentTypeAlias</p>
}
If you had a separate doc type about you could select that node.
@{
var home = Model.Content.AncestorOrSelf("home");
var about = home.Descendant("about");
}
You could then work with its children
@foreach (var item in about.Children())
{
<p>@item.Name, @item.DocumentTypeAlias</p>
}
Or even filter the children again by doctype
@foreach (var item in home.Children("articleWithImage"))
{
<p>@item.Name, @item.DocumentTypeAlias</p>
}
Thank you so much for your answer with some well explained ways .
But my question remains intact.
what if i have multiple pages even of some general type like 'article' for instance.
Is there any way to get exact number number of pages using 'article' doctype. ???
Reason for this..in my case is ..i want to give all <div> in my page their IDs,so that i can scroll to that section.
Get list of distinct document type under a node.
I have a document type named "home2" and it has various template allowed to used when creating page.how do i get unique list of DocumentType alias..I have written this code..which gets all children of "home2" and returns their doctype alias..but i want distinct list.
Cause I may have two pages of same doctype:
I am really stuck in this one..please help
Hi Bhawna,
Having 1 document type with multiple templates can sometimes get a little fragile, you might find it easier if you have a 1 to 1 relationship between Document Types and Templates, giving you more structure within your content - which should make it easier to query nodes / separate concerns.
Example:
Doctype:
home
=> Template:home
Doctype:
about
=> Template:about
For your generic pages, you could perhaps then have an
article
document type too.Umbraco has a handy feature that allows you to change a document type by right clicking on the node in the content tree. This is super handy, as it means you can adjust and refine the structure as your are working.
In response to your question, I've included some code below, that shows how to make the content queries in a slightly different and hopefully clearer way.
Example:
If you had a separate doc type
about
you could select that node.You could then work with its children
Or even filter the children again by doctype
Hope that gives you some ideas and helps!
Good luck, Laurie
Hi Laurence,
Thank you so much for your answer with some well explained ways . But my question remains intact.
what if i have multiple pages even of some general type like 'article' for instance. Is there any way to get exact number number of pages using 'article' doctype. ???
Reason for this..in my case is ..i want to give all
<div>
in my page their IDs,so that i can scroll to that section.Hello
Also be sure that you are not using "uQuery.GetNodesByType" and "Descendant", it's really heavy methods, look how to avoid it here - https://our.umbraco.org/documentation/reference/Common-Pitfalls/
Thanks
Alex
is working on a reply...