People playing around with the new features of Liferay may have noticed something very interesting when creating web content structures. What is it you might ask? It is a way to embeded web content articles into other articles!
But wait, how do I use this stinking thing?
Using DDM Journal Article Structure
If you've already tried to use this you may notice that when you use the usual
getData() it returns a JSON string containing the
classPK of the article. Cool, but I don't have access to
serviceLocator and don't know how to get the display of the content. Well you can, thanks to
<@liferay_ui['asset-display'] />. Lets see the template.
As we can see above, by using the taglib we are able to pass in those two values that the structure gives us and display our web content. Because we are referencing the primary key of the article, if we make revisions those changes will be reflected when displaying the content.
But why should I care?
Good question, I mean this is a cool feature but how does it help accomplish your needs? Imagine you've created some great copy that you want to use throughout your site. You want to use it on a landing page with some other content to make some nice columns, but you also want to include it by itself on another page. And who wants to repeat themselves? With this, you can make your content and get it looking exactly how you need it to look, then you can use this new structure type to embeded it wherever you need it! And since you are creating a new template, you can rearrange how you want the articles to be displayed on the page without changing the embeded articles template.
But wait, there is more...
Imagine that I do want to change the template of the embeded article so that the markup is different depending on how it is being used. Lets look at some templates:
In this template I am using
freeMarkerPortletPreferences.setValue("view", "basicContentView") to set my own custom preference. I've given it a value that is unique so that nothing else is disrupted. And here is another template where I am using the Bootstrap 3 markup for the carousel:
Again I am using the same pattern to set a unique view preference. But what about in the template I am embedding? I've created a basic structure and template for displaying a picture and some text. But I want to display it differently if I am creating a carousel or displaying them all together. So lets take a peak at how this affects my card template:
In this template we check to see what view has been set, and provide a default view if none is set. Look at this gif to see this in action:
The two web content articles on the left are displaying the web content articles on the right. You can see the template's I've included above to see how using the preferences to set a custom value allows us to change the way a web content template is displayed on the page.
Enjoy using this new feature!