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;
    var rootObject = TridionHelper.Engine.GetObject(rootSG.Id);
    foreach (var sg in rootObject.GetListItems())
        <div>@sg.OuterXml</div> @* this works.. *@

  • 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


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 you have read our privacy policy.

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