Documentation Center

Handling embedded fields in a Component

Some Components may contain embedded fields, that is, fields that are grouped together in a single Component field. For example, a Component may contain an Address field that contains the embedded fields Street, HouseNumber, ZipCode, and Municipality.

Content Manager example

To access these embedded fields in the Content Manager, navigate the data structure as in the following example:

// Define a filter to return only Components.
Filter filter = new Filter();
filter.Conditions["ItemType"] = ItemType.Component;
// Get the Publication identified by publicationURI;
Publication publication = (Publication) engine.GetSession().GetObject(publicationURI);
// Get the list of Components in the root Folder of the Publication;
IList<RepositoryLocalObject> list = publication.RootFolder.GetItems(filter);
Component firstComponent = (Component)list[1];
// Get the Fields of the first Component in that list;
ItemFields firstFields = new ItemFields(firstComponent.Content, firstComponent.Schema);
// Check for a field called Address, and verify that it is embedded.
if (firstFields.Contains("Address")) {
	EmbeddedSchemaField addressField = firstFields["Address"] as EmbeddedSchemaField;
	if (addressField != null) {
		IList<ItemFields> addressFieldValues = addressField.Values;
		foreach (ItemFields innerFields in addressFieldValues) {
			if (innerFields.Contains("Street")) {
				log.Info("Street name = " + innerFields["Street"]);
			}
		}
	}
}

Package example

To access these embedded fields in a package, access the package as in the example below.

// The Component has a field of type Embedded Schema named Address,
// and the embedded Schema has an embedded field called Street.
string street = package.GetValue("Component.Fields.Address.Street");