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.

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;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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