Get Layout Friendly URL In Liferay

Rashidi Zin picture Rashidi Zin · Nov 14, 2013 · Viewed 13.8k times · Source

I want to get a friendly URL for a layout based on layout id. For example, /web/group/page. Currently this is how I do it:

Layout layout = LayoutLocalServiceUtil.getLayout(groupId, false, layoutId);

String groupFriendlyUrl = GroupLocalServiceUtil.getGroup(groupId).getFriendlyURL(); //will output /group
String layoutFriendlyUrl = layout.getFriendlyURL(); //will output /page
String webFriendlyUrl = String.format("/web%s%s", groupFriendlyUrl, layoutFriendlyUrl); //will output /web/group/page

I am wondering if there is a better way to do this where I can the full path, /web/group/page with one method.

Answer

Khiem Tran picture Khiem Tran · Jun 29, 2014

If you have plid (Page layout Id), use getLayoutFriendlyURL() like below:

Layout selectedLayout = LayoutLocalServiceUtil.getLayout(plid);
String url = PortalUtil.getLayoutFriendlyURL(selectedLayout, themeDisplay);