You want to have a link to a WebContent in Liferay, to send to a colleague or a friend. This friend should then look at the WebContent without having to navigate through Liferay. And : This should be as flexible as possible, without having to create a WebContent Display Portlet for each created WebContent.
Solution
There are actually two solutions:
1 Linking diretly to the WebContent:
If you link diretly to the WebContent, the WebContent is shown without showing the Portal itself. Just as you would link directly to an html page. This is what you need to do to get the link:
1.1
Add portalURL and pathMain together to create a link to the Server Liferay is running on :
String pathToWebContent = themeDisplay.getPortalURL() + themeDisplay.getPathMain();
2.1
Add the Path to directly view a WebContent:
pathToWebContent += "/journal/view_article_content?groupId="
Add GroupId, ArticleId and Version of the WebContent you want to display :
pathToWebContent += journalArticle.getGroupId() + "&articleId=" + journalArticle.getArticleId() + "&version=" +journalArticle.getVersion();
http://localhost:8080/c/journal/view_article_content?groupId=12041&articleId=73245&version=1.0
2 Linking to an asset publisher
If you want to display the WebContent IN the portal, so that the User afterwards can start to explore your portal (maybe you want to lure some customers onto your website) you can do the following :
To summarize it : We deploy an Asset Publisher Portlet to the portal, search this Asset Publisher in our code and pass the Web Content data to it.
2.1 Prepare the portal
At first, create a new site in your portal, that will only take an asset publisher. Then deploy an asset publisher somewhere on that page. This asset publisher will now be the place where all your web contents will be displayed. Enter the Configuration of the asset publisher and change "asset selection" to "manual". That´s all for the asset publisher.
The last thing you have to do is to remember the friendly url that leads to your asset publisher. Look at the status bar of your browser : http://localhost:8080/user/admin/test. In this case it would be "test".
2.2 Navigate to the asset publisher
What your method needs is the friendly url ("test") and the journalArticle (= Web Content) to navigate to the asset publisher. So how do we navigate there ?
First, retrieve all Layouts and inspect the friendlyURL property if it equals the friendly URL you passed into the method:
List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(QueryUtil.ALL_POS, QueryUtil.ALL_POS);[...]if (friendlyURL.equals("/" + friendlyUrl)) ...
UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();String property= typeSettingsProperties.getProperty("column-2");
If you have this property, you need the instance ID of the asset publisher to build the link correctly:
String assetId= property.subString(property.indexOf("_INSTANCE_") + 10);
String url = getUserPage() + "/" + friendlyUrl + "/-/asset_publisher/" + assetId+ "/content/" + journalArticle.getUrlTitle();
If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)
If you have any questions, feel free to leave a comment.
Hello,
AntwortenLöschenI am using Liferay 6.0. In previous version (5.2.3) I had something like this /home/-/journal_content/56/10122/30819. This is the link for maximize portlet view. Every thing was working property but after upgrade on 6.0 ver I have a problem. When I click on this URL portlet display You do not have the roles required to access this portlet.
I will investigate. Be sure to check this post in a day or so ...
AntwortenLöschenThis can work, but for this all those which need to be linked with a web content have to be Text Box(Html). So if your structure contains 15 fields out of which you need 5-6 to be linked with Web Content, the system may get slow. (See in broader perspective, if you have thousands of such contents).
AntwortenLöschen