Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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.
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.
How do you use ContentHelper to get the list in the first place?
You "should" be able to do a little something funky with the DocumentTypeBase returned by GetChildren:
var children = ContentHelper.GetChildren(CurrentModel.Id,true).Where( x => x is Planet);
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.
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.
Ah yes, I normally do that. Thanks.
Write your reply to:
Image will be uploaded when post is submitted