How to get all nodes that inherit a particular base doc type?
Hello,
I'm familiar with ContentHelper.GetChildren<T> which will give me a list of nodes that are of a particular doc type but I have the following doc type structure:
Planet -- Mercury -- Venus -- Earth -- Mars
So all my various planets inhert from the base 'Planet' doc type.
These planet nodes will be scattered about in my content so I won't know which particluar type I'm looking for when I'm on a particular node, I just know there will be one:
Yes that possible, we do the same thing. We tend to use interfaces though, for instance we a ISocialMediaItem base class which various other doctypes can extend (or a base doc type if you want to save some work) for twitter, facebook, etc. yet we can render all of them out by passing a list of ISocialMediaItem to our templates.
Don't forget to mark answers as "Solved" when people answer correctly. That helps people who are trying to help to see which questions still need answering but also helps other people who are searching for answers to easilly identify the right answer.
In this case I believe Pete's answer should be marked as "Solved" and you're the only one who can do it because you opened this thread.
How to get all nodes that inherit a particular base doc type?
Hello,
I'm familiar with ContentHelper.GetChildren<T> which will give me a list of nodes that are of a particular doc type but I have the following doc type structure:
Planet
-- Mercury
-- Venus
-- Earth
-- Mars
So all my various planets inhert from the base 'Planet' doc type.
These planet nodes will be scattered about in my content so I won't know which particluar type I'm looking for when I'm on a particular node, I just know there will be one:
Content Root
-- Node 1
---- Mars
-- Node 2
---- Earth
-- Node 3
---- Earth
Is there a way I can neatly query the child nodes to get any of the planets with out specifying their particular doc type?
Something like ContentHelper.GetChildren<DocumentTypes.Planet> but it returns anything that inherits from Planet.
Regards,
Matt
Hi Matt,
Yes that possible, we do the same thing. We tend to use interfaces though, for instance we a ISocialMediaItem base class which various other doctypes can extend (or a base doc type if you want to save some work) for twitter, facebook, etc. yet we can render all of them out by passing a list of ISocialMediaItem to our templates.
Works a treat.
Pete
Thanks Peter,
How do you use ContentHelper to get the list in the first place?
Regards,
Matt
You "should" be able to do a little something funky with the DocumentTypeBase returned by GetChildren:
That should give you a list of just Planet doctypes or anything that inherits from Planet. (http://msdn.microsoft.com/en-us/library/scekt9xw(v=vs.71).aspx)
Great Peter, you're the man of the week.
Hey Matt,
Don't forget to mark answers as "Solved" when people answer correctly. That helps people who are trying to help to see which questions still need answering but also helps other people who are searching for answers to easilly identify the right answer.
In this case I believe Pete's answer should be marked as "Solved" and you're the only one who can do it because you opened this thread.
Regards,
Sasa
Ah yes, I normally do that. Thanks.
is working on a reply...