[Tridion beginner]
I have a folder named Components
where I store different Components. Now, I would like (in C# code fragment template building block that I put in component template) to get list of components from this folder, based on certain schema, and put them in package, so I can later render them from DWT template building block.
This is what I have:
<%@Import Namespace="Tridion.ContentManager.ContentManagement"%>
// run template with article component, so that article schema is processed
string componentID = package.GetValue("Component.ID");
Component articleComponent = (Component)engine.GetSession().GetObject(componentID);
// Get the Schema of articleComponent
Schema articleSchema = articleComponent.Schema;
// get the folder of current component
Folder componentsFolder = (Folder) articleComponent.OrganizationalItem;
// Create a object of class Filter to filter retrieved content items.
Filter filter = new Filter();
// Filter out all items that are not based on the Schema called articleSchema.
filter.Conditions["BasedOnSchema"] = articleSchema.Id;
// Make the call to GetListItems() using this Filter object. For each item, the default set of items is returned.
XmlElement listOfComponents = componentsFolder.GetListItems(filter );
package.PushItem("listOfComponents", package.CreateStringItem(ContentType.Text, listOfComponents.ToString()));
I have pushed XmlElement as String in package so I could see what am I getting, but all I get is just one line - "XmlElement". What am I doing wrong with reading components from folder, because there are couple components with appropriate schema in this folder.