4
  • I define a menu in navigation.vm file which working good in liferay project.
  • But I want to access this menu from my portlet.
  • Is there any way to access menu from portlet entry point or view.jsp????
Moddasir
  • 1,449
  • 13
  • 33

2 Answers2

1

import liferay-ui taglib:

<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>

then you can use

<liferay-ui:navigation displayStyle="from-level-0" >
</liferay-ui:navigation>

Note: setting displayStyle="from-level-0" to give you the normal behavior like on navigation.vm, you can play with attributes differently to get other behavior.

Prakash K
  • 11,669
  • 6
  • 51
  • 109
Ahmedbc
  • 76
  • 3
0

This link describes the way of getting menu items in a jsp directly.

The below code is reproduced directly from the above link with some improved formatting:

<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.liferay.portal.model.Layout"%>
<%@ page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@ page import="com.liferay.portal.theme.NavItem" %>
<%@ page import="com.liferay.portal.theme.RequestVars" %>
<%@ page import="com.liferay.portal.theme.ThemeDisplay"%>

<portlet:defineObjects />

<liferay-theme:defineObjects />

<div style="width:100%">
<%
//ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

String title = themeDisplay.getLayout().getName(themeDisplay.getLocale());

List<NavItem> navItems = new ArrayList<NavItem>();

if (layout != null) {
    RequestVars requestVars = new RequestVars(request, themeDisplay, layout.getAncestorPlid(), layout.getAncestorLayoutId()); 
    navItems = NavItem.fromLayouts(requestVars, layouts);
}

for (NavItem navItem : navItems) {
    if (navItem.getName().equalsIgnoreCase(title)) {
        if (navItem.hasChildren()) {

            for(NavItem navChild : navItem.getChildren()) {
%>

    <div style="float:left;" class="newsMenuPortlet">
        <a href="<%= navChild.getURL() %>" <%=navChild.getTarget() %>>
            <%= navChild.getName() %>
        </a>
    </div>

<%
            } // inner for-loop ends here
        }
    }
}// outer for-loop ends here
%>

</div>
Prakash K
  • 11,669
  • 6
  • 51
  • 109
mridul4c
  • 8,197
  • 3
  • 19
  • 28