Search code examples
tridiontridion-2011

How to include Dynamic component presentation in the tridion page?


How to include/refer a dynamic component template in the page. I had created a dynamic CT and published it, but want to render its presentation in the page. Please suggest.

Thanks in advance,


Solution

  • There are many ways to add dynamic presentation on the page.

    Direct Approach - For this your component presentation should be allowed to on page. Check Allow on Page Using Dynamic Assembly. Add the presentation on page same as all others.

    Code Approach - You may use API to get your component presentation direct from the broker storage. Here is sample code for the same.

    *<%@ Import Namespace="Tridion.ContentDelivery.DynamicContent"%>
    <%
      ComponentPresentationFactory factory = new ComponentPresentationFactory();
      ComponentPresentation ps = factory.getComponentPresentation("CompID","TEMPLATEID");
      Response.Write(ps.Content);
    %>
    JSP example:
    
    <%@ page import="com.tridion.dynamiccontent" %>
    <% 
      ComponentPresentationFactory cpf = new ComponentPresentationFactory("tcm:0-1-1"); // Publication URI
      // Component URI and Component Template URI
      ComponentPresentation componentPresentation = cpf.getComponentPresentation("CompID", "TEMPLATEID");
      out.println(componentPresentation.getContent());
    %>
    

    c#

    ComponentPresentationFactory cp_factory = new ComponentPresentationFactory(publicationid);
    ComponentPresentation cp = cp_factory.GetComponentPresentation(CompID, TEMPLATEID);
    if (cp != null)
      {
         Output = cp.Content;
    }