Adding raw Component Presentation content to a Web page
Use the ComponentPresentationFactory class to add Component Presentation content 'as is' to a Web page.
To retrieve raw Component Presentation content, first create a Component Presentation Factory:
ComponentPresentationFactory factory = new ComponentPresentationFactory();
The factory can then be used to get a Component Presentation in one of the following ways (all examples are JSP):
Supplying a Component ID in combination with a template ID:
ComponentPresentation ps = factory.getComponentPresentation("tcm:12-123", "tcm:12-55-32");Supplying the ID that results in the Component with the highest priority:
ComponentPresentation ps = factory.getComponentPresentationWithHighestPriority("tcm:12-123");
If a URI is available for the ComponentPresentation, the following code can be used:
ComponentPresentation ps1 = factory.getComponentPresentationWithHighestPriority(new TCMURI("tcm:12-123").getItemId());
You can now use the Content field of the object to retrieve the raw content of the Component Presentation.
ASP.NET example:
<%@ Import Namespace="Tridion.ContentDelivery.DynamicContent"%>
<%
ComponentPresentationFactory factory = new ComponentPresentationFactory();
ComponentPresentation ps = factory.getComponentPresentation("tcm:12-123","tcm:12-55-32");
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("tcm:1-234", "tcm:1-345:32");
out.println(componentPresentation.getContent());
%>