Copied to clipboard

Flag this post as spam?

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


  • gilad 185 posts 425 karma points
    Dec 26, 2011 @ 20:53
    gilad
    0

    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.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Dec 27, 2011 @ 00:50
    Sebastiaan Janssen
    0

    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?

  • gilad 185 posts 425 karma points
    Dec 27, 2011 @ 08:56
    gilad
    0

    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!

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 27, 2011 @ 10:25
    Dirk De Grave
    1

    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

     

     

  • gilad 185 posts 425 karma points
    Dec 27, 2011 @ 10:30
    gilad
    0

    Hii dirk, good idea...

    HasProperty return true also if property is empty?

    Thanks!

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 27, 2011 @ 10:36
    Dirk De Grave
    0

    Don't think so, HasProperty() only checks whether document has a property with specified alias. If HasProperty() returns true, just do a

    node.getProperty('alias').Value

    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

  • gilad 185 posts 425 karma points
    Dec 27, 2011 @ 10:40
    gilad
    0

    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.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Dec 28, 2011 @ 19:40
    Sebastiaan Janssen
    0

    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.

  • gilad 185 posts 425 karma points
    Dec 28, 2011 @ 20:04
    gilad
    0

    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.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Dec 28, 2011 @ 20:12
    Sebastiaan Janssen
    0

    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.

  • gilad 185 posts 425 karma points
    Dec 29, 2011 @ 10:40
    gilad
    0

    hii.

    ok , so - HasProperty make the job...

    Do not know why I had trouble with it

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft