问题
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,
回答1:
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;
}
回答2:
There is multiple ways to show a Dynamic Presentation on a page:
- the most simple one is marking your Dynamic CT as
"Allow on Page Using Dynamic Assembly"
, then you will be able to embed it on your page as a Non-Dynamic CT

- For more advanced alternatives, you can check the Live Content Documentation: Implementing Content Delivery > Developing Web Pages
来源:https://stackoverflow.com/questions/12799509/how-to-include-dynamic-component-presentation-in-the-tridion-page