I am trying to get some information from Dynamic Component Presentation through a Java program.
I have published Dynamic Component called ABCD from Tridion 2011 SP1.
Do we have any tutorials online to learn from?
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It only takes a minute to sign up.Sign up to join this community
I am not sure you'll find something close to a tutorial, most of the active bloggers/participants in the Tridion Community learned how to do this before there was an active online community.
Things to take into consideration:
ComponentPresentationAssembler. If your DCP has any dynamic code in it (like dynamic linking) then you should use
ComponentPresentationAssembleron the 2013 doc and got 8 pages with examples.
Criteriaclasses to run a query.
And, of course, don't forget to ask here whatever else you find that gets you stuck.
Use the ComponentPresentationAssembler class to execute any code in the Component Presentation, then add the result to the Web page.
The ComponentPresentationAssembler class assembles Dynamic Component Presentations on a Page. You can use the Component Presentation Assembler to dynamically add content of Dynamic Component Presentations to the content of your Page. The Component Presentation Assembler invokes handlers for JSP, ASP and XML/XSLT content.
<%@ page import="com.tridion.web.jsp.JSPPage, com.tridion.web.jsp.ComponentPresentationAssembler" %> <% JSPPage dcdPage = new JSPPage(pageContext, "tcm:28-834-64"); ComponentPresentationAssembler cpAssembler = new ComponentPresentationAssembler(dcdPage); out.println(cpAssembler.getContent("tcm:28-780","tcm:28-821-32")); %>
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();
<%@ 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()); %>