2

I have a traditional non-DD4T website in Tridion 2011 SP1 where in I have queried for a component from Broker db using content delivery query/criteria. I have received the tcm id of the component and now looking for accessing the fields inside it using ComponentFactory. I am getting error on the first line below code asking to provide a namespace for ComponentFactory-

ComponentFactory compf = new ComponentFactory();

var comp = compf.GetComponent(tcmid); //tcmid returned from ExecuteQuery()

I understand that in DD4T we have DD4T.Factories NS to make it work but I want it to work with the normal content delivery NS if at all available for ComponentFactories. As DD4T uses the normal Content Delivery APIs only then the NS should be there but I am not able to find it?

4
  • 2
    The component fields are a DD4T concept, it is loading & parsing the content of a component presentation. In non-DD4T all you have is the actual output from Tridion, which may or may not be well formed.
    – Nuno Linhares
    Feb 27, 2014 at 19:09
  • Additionally to what @Nuno said, if you take a look at the DD4T source code, you will also see what Tridion namespaces it uses, see for example code.google.com/p/dynamic-delivery-4-tridion/source/browse/… and the Tridion.ContentDelivery namespaces in there... Feb 28, 2014 at 8:41
  • @Bart, I want to use ComponentFactory in non-DD4T website to fetch the fields of any component published dynamically in my page templ tbb. I am using a dummy CT which doesn't reads the fields so can't use ComponentPresentationFactory or assembler. It seems the class is not available in normal content delivery.
    – user932
    Feb 28, 2014 at 10:10
  • @user932 you cannot compare DD4T with anything that is not DD4T, so you also shouldn't expect the same functionality. If you need the features of DD4T, use DD4T, if not then you will most likely need to build them yourself, see also the comment of Nuno Linhares Feb 28, 2014 at 10:16

1 Answer 1

3

First of all where did you find that ComponentFactory, wouldn't that also tell you what namespace it belongs to?

As for using the Broker API, start with reading the documentation (requires login). Then you will see that you can use the Querying API you mention roughly as follows:

using Tridion.ContentDelivery.DynamicContent.Query;
using Tridion.ContentDelivery.DynamicContent;

StringBuilder sb = new StringBuilder();
string templateUri = "tcm:2-29-32";
int publicationId = 2;

using (ComponentPresentationAssembler cpa = new ComponentPresentationAssembler("tcm:0-0-0", Page))
using (ComponentPresentationFactory cpf = new ComponentPresentationFactory(publicationId))
{
    // get list of all Components for this Publication based on a given Schema
    Criteria itemTypeCriteria = new ItemTypeCriteria(16);
    Criteria schemaCriteria = new ItemSchemaCriteria(27);
    AndCriteria criteria = new AndCriteria(itemTypeCriteria, schemaCriteria);

    Query query = new Query(criteria);
    string[] result = query.ExecuteQuery();
    foreach (string uri in result)
    {
        // get Component Presentation for found Component
        using (ComponentPresentation cp = cpf.GetComponentPresentation(uri, templateUri))
        {
            if (cp != null)
            {
                // use ComponentPresentationAssembler since cp.Content does not resolve REL
                sb.Append(cpa.GetContent(string.Format("tcm:{0}-{1}", publicationId, cp.ComponentId), 
                           string.Format("tcm:{0}-{1}-32", publicationId, cp.ComponentTemplateId)));
            }
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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