@foreach(var page in CurrentPage.Children.Where( "Visible" ))
{
Now I want to search through specific pages, namely Cafe and Information
I tried:
@foreach(var page in CurrentPage.Children.Where(DocumentTypeId == "cafe", "Visible" ))
{
for starters just to get the cafe one working, but there was an error telling me that I couldn't use DocumentTypeId here. Is there a way of doing this? If not I can just make new document types and do it that way!
Crikey lads I went out for lunch and all this info!!
Thanks a lot. That's exactly what I've been trying to do, like what Jeavon said and Jan said about the Id (somebody could change the names all right!).
Thanks Dennis - I was wondering how to use && and || too.
I think that if possible then the best approach is to look for aliases if possible. If you know that everytime there is a document type of a certain alias then you want to do something specifically with that alias.
If it's a certain page then it might be a good idea to use a checkbox on the page(s) so you can look for pages with the flag set and then do something specific to them. Looking for an ID can be fragile as well if someone by accident deletes the node and just creates a new one without restoring the original node. Then the site could break because the ID does no longer exist. Looking for a named node is also bad since if the name is changed the node won't be found.
So aliases or checkboxes is usually the best practice. Perhaps even looking for "template" id's a some times as well.
Just a little more input so you know what to consider for the different scenarios. Hope it's useful as well.
I used the DocumentTypeAlias and got it to work. In this instance nobody will be deleting the document type - luckily for me as I couldn't get the node id to work! I got the id from the Content area under Properties, but it must be wrong!
The ID under the properties tab of a content node is the node ID for that specific piece of content not the type. What you were using originally was DocumentTypeId .. If ou want that if then you get that from settings > document types (on the move so not sure where exactly)!
Ah yes, sorry my bad! Steve is absolutely right about that one about the documenttypeid...I initially read "DocumentId". Very important distinction. And if you use the document type id then there is nothing to worry about either, unless you delete the document type but that's very unlikely.
Tony - you're quite right the DocumentTypeAliasId is not visibile in the Umbraco GUI! TBH judging on forum and blog posts "the community" generally just uses the alias anyhow (I know I do!).
To get the Id the easy ways are to use Visual Studio and inspect or write it out on a test page / quick change to a Razor script :)
Thanks Steve I thought it was hidden from me or I was going mad!! Problem well solved! It's great to find all the other ways - just in case for another day.
At the moment it's not broke, so I'll leave it that way!!
Use of .Where()
Hi All
I have this piece of code:
@foreach(var page in CurrentPage.Children.Where( "Visible" ))
{
Now I want to search through specific pages, namely Cafe and Information
I tried:
@foreach(var page in CurrentPage.Children.Where(DocumentTypeId == "cafe", "Visible" ))
{
for starters just to get the cafe one working, but there was an error telling me that I couldn't use DocumentTypeId here. Is there a way of doing this? If not I can just make new document types and do it that way!
Thanks
Tony
Hi Tony,
I think you are after something like this:
Jeavon
Hi Tony
In order for that to work you'll need to pass the id rather than the pagename I guess.
If you look under the "Properties" tab for the pages you can find the id's. Try passing them instead of "cafe".
Hope this makes sense.
/Jan
You could filter by name
But it would break if a editor changed the name, probably best to go with the ID as Jan suggests
Jeavon
Or create unique document types, then
Hi Tony,
And if you need to filter on more than one document type in the where, you will do it like this.
/Dennis
Crikey lads I went out for lunch and all this info!!
Thanks a lot. That's exactly what I've been trying to do, like what Jeavon said and Jan said about the Id (somebody could change the names all right!).
Thanks Dennis - I was wondering how to use && and || too.
:)
Sorted!
Hi Tony
Yeah, it's nice right? :)
I think that if possible then the best approach is to look for aliases if possible. If you know that everytime there is a document type of a certain alias then you want to do something specifically with that alias.
If it's a certain page then it might be a good idea to use a checkbox on the page(s) so you can look for pages with the flag set and then do something specific to them. Looking for an ID can be fragile as well if someone by accident deletes the node and just creates a new one without restoring the original node. Then the site could break because the ID does no longer exist. Looking for a named node is also bad since if the name is changed the node won't be found.
So aliases or checkboxes is usually the best practice. Perhaps even looking for "template" id's a some times as well.
Just a little more input so you know what to consider for the different scenarios. Hope it's useful as well.
/Jan
Hi Jan
Thanks for that.
I used the DocumentTypeAlias and got it to work. In this instance nobody will be deleting the document type - luckily for me as I couldn't get the node id to work! I got the id from the Content area under Properties, but it must be wrong!
There's for and against each approach all right!
Thanks
Tony
The ID under the properties tab of a content node is the node ID for that specific piece of content not the type. What you were using originally was DocumentTypeId .. If ou want that if then you get that from settings > document types (on the move so not sure where exactly)!
Hth
Steve
Ah yes, sorry my bad! Steve is absolutely right about that one about the documenttypeid...I initially read "DocumentId". Very important distinction. And if you use the document type id then there is nothing to worry about either, unless you delete the document type but that's very unlikely.
/Jan
I looked under Settings and Documents before for a node id but couldn't find any - that's why I went with the DocumentTypeAlias!
Thanks Steve & Jan
Tony
Tony - you're quite right the DocumentTypeAliasId is not visibile in the Umbraco GUI! TBH judging on forum and blog posts "the community" generally just uses the alias anyhow (I know I do!).
To get the Id the easy ways are to use Visual Studio and inspect or write it out on a test page / quick change to a Razor script :)
Glad you've got your problem sorted anyhow!
Steve
Thanks Steve I thought it was hidden from me or I was going mad!! Problem well solved! It's great to find all the other ways - just in case for another day.
At the moment it's not broke, so I'll leave it that way!!
Tony
I use:
.Where ("documentTypeAlias == \"aliasName\"")
I like this one by Dennis
If I were to use that method I would remove the duplication of DocumentTypeAlias, so it would be something like this.
is working on a reply...