2

I would like to get the Root Structure Group and then iterate through all immediate children of it using the Razor Mediator.

Getting the root StructureGroup works, but it is a StructureGroupModel object. Calling GetItems on this gives me an error.

Casting it to a StructureGroup object works, but calling GetItems on that also returns the same error about it being a property. GetListItems does work (see code), but then I need to supply the ItemType filter, and that is quite challenging.

Questions: Is it possible to iterate through the direct children of the Root StructureGroup in Razor? How would I declare an ItemType filter to only the Structure Groups?

@{
    var rootSG = Publication.RootStructureGroup;
    <div>@rootSG.GetType()</div>
    var rootObject = TridionHelper.Engine.GetObject(rootSG.Id);
    <div>@rootObject</div>
    foreach (var sg in rootObject.GetListItems())
    {
        <div>@sg.OuterXml</div> @* this works.. *@
    }

}
2
  • 1
    Aren't you trying to do too much coding in a template here? This starts to look a bit like those ugly old VBScript Templates to me... Feb 25, 2015 at 9:42
  • Haha...you do have a point! We could also do this in a C# TBB, but what key value pair would you push to the package for the title and URL?
    – robrtc
    Feb 25, 2015 at 11:02

1 Answer 1

3

you can try below code, I havn't run this though.

OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(TridionHelper.Engine.GetSession());
            filter.Recursive = true;
            filter.ItemTypes = new[] { ItemType.StructureGroup };
List<RepositoryLocalObject> SgItems = (List<RepositoryLocalObject>)rootObject.GetItems(filter);

// you can use GetListItems as well according to the need

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.