Message Boards

programmatically create and render web content in liferay 7.2

FABIO PORTIERI, modified 4 Years ago.

programmatically create and render web content in liferay 7.2

New Member Posts: 6 Join Date: 10/22/19 Recent Posts
Hi all. It's my understanding that in liferay 7.2 the journal api are deprecated, and that we should always create web content with a structure and a template. I found some examples on the net in how to achieve so, the thing i am missing is how to retrieve the content for page rendering, since all the examples i've seen so far make use of the journal api Also can you recommend me some good resource with examples for liferay 7.2 apithank you in advance
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: programmatically create and render web content in liferay 7.2

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hey Fabio,The journal API is deprecated? I would be surprised of that was a true statement. WCM, is one of the pillars of Liferay. Deprecating the Journal API would be a big problem for long time users. 7.2 did introduce a Headless API that you can use to access different things including the Journal API, perhaps that is what you are thinking of?
There is also further improvements to the Page Fragments which is also a form of WCM -- more in context and sometimes referred to as "unstructured" content management. Regardless, the journal feature is still critical and still active -- at least to my knowledge.

Rendering a content item can be done in a few ways. Assuming that you are not using a Web Content portlet and you are asking how to retrieve the markup using the journal API, there are a few methods on the JournalArticleLocalService that you can  leverage, one of which is the JournalArticleLocalService#getArticleContent method.
As you mentioned, structures and templates are key for this to work. Structures can be looked up using the DDMStructureLocalService and templates using the DDMTemplateLocalService. Once you have the Article, Structure and Template, tehn you should have everything you need to generate the HTML which you can then do whatever you want with.