Could you give an example of what your site structure (and therefore document type structure) looks like and what exactly you're trying to do with that?
i'm buliding a menu and loop through some nodes...
for each node i want to check if this node document type is children/grandchild of other document type.
example :
lets say - i want to check if some node document type ischildren/grandchildof document type with allias 'pageSetting' to check if this node is page or some data entity.
so if some node document type is - 'contentPage'.
this node not have a parent with 'pageSetting' document type in site structure.
but 'contentPage' is children of 'pageSetting' in document type structure.
I'd use HasProperty('alias') for that. If that returns a Property object, then you're sure your document is of a document type which inherits from pageSettings (either as child or grandchild)
HasProperty should only return false if the property does not exist in that document type. What you're referring to is HasValue, so this is the safest way to check both:
@if (node.HasProperty && node.HasValue("myPropertyAlias")) { // do something }
What I think you want to do though is check if any of an item's ancestors has a property called pageSettings with a value, correct?
You can do this:
@foreach (var item in yourMenuItemsList) { if(string.IsNullOrEmpty(item._myPropertyAlias) == false) { // hey, this alias has a value on one of the nodes above me, let's do something } }
The underscore is doing the recursion for you, so it's looking: Do I have a "myPropertyAlias" with a value? If not, does my parent? If not, does my parent's parent? And so on.
that not exactly what i want to do but i think that could help.
i try to explain again what i want to do :
i want to check if the document type of node is inherits from document type with allias "pageSettings".
i dont care if he has value in some property or not...
i just want to check if this node documentType is inherits from "pageSetting" - then i could know that this node should have a private page and display a link.
( this node also can be a data for some lobby , and then i dont want to put it in my menu or site map.. ) - in this case this node document type do not inherits from document type "pageSetting".
Wow, that seems like a really complex way to do things.
There is no direct way to know if a documentType is inheriting from another document type.
One thing I can think of is putting a property on the pageSetting document type that is guaranteed not to appear on other document types. This can be a property of type "Label" for example, so it will never have a value. You can still check with HasProperty if the property exists on the current page (@Model.HasProperty("myUniquePropertyAlias")) or if you still need to check the parent/grandparents/ancestors, like I describe above. I think you can use the recursive call but just say if(item._myUniquePropertyAlias != null) or something. I haven't tested this though so you might need to build your own recursive function that loops through the parents and does a .HasProperty() call.
check document type structure
hello everyone.
i need to check if some node document type is children/grandchild of other document type
( not in content section , in setting section ) , it is possible?
hope it is clear.
thanks in advance.
I'm not sure exactly what you intend to do...
Could you give an example of what your site structure (and therefore document type structure) looks like and what exactly you're trying to do with that?
hii sebastiaan.
i'm buliding a menu and loop through some nodes...
for each node i want to check if this node document type is children/grandchild of other document type.
example :
lets say - i want to check if some node document type is children/grandchild of document type with allias 'pageSetting' to check if this node is page or some data entity.
so if some node document type is - 'contentPage'.
this node not have a parent with 'pageSetting' document type in site structure.
but 'contentPage' is children of 'pageSetting' in document type structure.
hope it is more clear now.
thanks!
I'd use HasProperty('alias') for that. If that returns a Property object, then you're sure your document is of a document type which inherits from pageSettings (either as child or grandchild)
Cheers,
/Dirk
Hii dirk, good idea...
HasProperty return true also if property is empty?
Thanks!
Don't think so, HasProperty() only checks whether document has a property with specified alias. If HasProperty() returns true, just do a
to get to the value.
(Be aware there's a difference in casing between GetProperty('') and getProperty(''), intelissense will tell you what to use)
Cheers,
/Dirk
hii dirk,
i don't need to get the property...
i think that HasProperty return false if property is empty..
then my check return false.. but still it is inherits from pageSettings.
Cheers.
HasProperty should only return false if the property does not exist in that document type. What you're referring to is HasValue, so this is the safest way to check both:
What I think you want to do though is check if any of an item's ancestors has a property called pageSettings with a value, correct?
You can do this:
The underscore is doing the recursion for you, so it's looking: Do I have a "myPropertyAlias" with a value? If not, does my parent? If not, does my parent's parent? And so on.
hii sebastiaan,
that not exactly what i want to do but i think that could help.
i try to explain again what i want to do :
i want to check if the document type of node is inherits from document type with allias "pageSettings".
i dont care if he has value in some property or not...
i just want to check if this node documentType is inherits from "pageSetting" - then i could know that this node should have a private page and display a link.
( this node also can be a data for some lobby , and then i dont want to put it in my menu or site map.. ) - in this case this node document type do not inherits from document type "pageSetting".
thanks.
Wow, that seems like a really complex way to do things.
There is no direct way to know if a documentType is inheriting from another document type.
One thing I can think of is putting a property on the pageSetting document type that is guaranteed not to appear on other document types. This can be a property of type "Label" for example, so it will never have a value. You can still check with HasProperty if the property exists on the current page (@Model.HasProperty("myUniquePropertyAlias")) or if you still need to check the parent/grandparents/ancestors, like I describe above. I think you can use the recursive call but just say if(item._myUniquePropertyAlias != null) or something. I haven't tested this though so you might need to build your own recursive function that loops through the parents and does a .HasProperty() call.
hii.
ok , so - HasProperty make the job...
Do not know why I had trouble with it
Thanks.
is working on a reply...