9

This code works to get content from the broker for all components whos name begins with "MC":

    Criteria c1 = new ItemTitleCriteria("MC%",  Criteria.Like);

    //Create query
    Query myQuery = new Query(c1);

    String[] itemURIs = myQuery.ExecuteQuery();
    ComponentPresentationAssembler cpAssembler = new ComponentPresentationAssembler();
    foreach (string componentUri in itemURIs)
    {
        String content = cpAssembler.GetContent(componentUri, componentTemplateUri);
    }

However, I am struggling to find in the api where I can actually access the names (or titles) of each component returned.

1 Answer 1

11

You can use the ComponentMetaFactory class to interrogate the metadata of your component.

Criteria c1 = new ItemTitleCriteria("MC%", Criteria.Like);

//Create query
Query myQuery = new Query(c1);

String[] itemURIs = myQuery.ExecuteQuery();
ComponentPresentationAssembler cpAssembler = new ComponentPresentationAssembler();
ComponentMetaFactory cmFactory = new ComponentMetaFactory(publicationId);

foreach (string componentUri in itemURIs)
{
    String content = cpAssembler.GetContent(componentUri, componentTemplateUri);
    IComponentMeta componentMeta = cmFactory.GetMeta(componentUri);
    string componentTitle = componentMeta.Title;
}
0

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.