Forums de discussion

Custom user menu in theme

Kousik Majumder, modifié il y a 9 années.

Custom user menu in theme

New Member Publications: 11 Date d'inscription: 04/04/13 Publications récentes
Hi All,

I am using Liferay 6.1. I want to create a menu based on the user who logged in. This username is shown at top right corner which stays in theme(because that is accessible from all the pages inside application). Remember this is not the so called menu of the application, rather an add on to the user menu who logs in. Now this menu needs to be dynamically created when I click on the user name. Somewhat like the attachment with a down arrow beside username.
This user name is coded inside the portal_normal.vm file.

So please suggest how can I create the dynamic menu on clicking the user name? I have seen navigation.vm file but I do not think that is going to solve my purpose because what I have understood is that navigation.vm takes care of the application menu structure. Right?
Also please give some sample code.


Thanks in advance.

Pièces jointes:

thumbnail
Olaf Kock, modifié il y a 9 années.

RE: Custom user menu in theme

Liferay Legend Publications: 6403 Date d'inscription: 23/09/08 Publications récentes
As far as I remember 6.1, the part you're talking about is part of the dockbar portlet. You can either modify that portlet (sorry, no demo code) or add your own custom portlet to the theme and style it so that it appears next to the dockbar.

Why does the dockbar portlet not look like any other portlet? Well, you can't do a lot with it (e.g. not drag/drop or configure it) and the default theme comes with fancy CSS to make it appear like it does.
Kousik Majumder, modifié il y a 9 années.

RE: Custom user menu in theme

New Member Publications: 11 Date d'inscription: 04/04/13 Publications récentes
Thank you for your reply Olaf. But docbar appears on the top of the page for admin user only in my project and I can not mix it with my portlet because it will not serve my purpose.
This menu I am talking about will appear for any user, only the sub menu content will change based on the user role. So is there any other way to accomplish it.Otherwise I think I will need a separate portlet and fit that on the top right corner to make it work. Ned to try that.
thumbnail
Olaf Kock, modifié il y a 9 années.

RE: Custom user menu in theme

Liferay Legend Publications: 6403 Date d'inscription: 23/09/08 Publications récentes
You could add yet another portlet with similar fancy css if you absolutely can't have this functionality combined with dockbar.

The implementation then can be straightforward - just embed your new portlet in the theme and have it generate the required content for the menu.
thumbnail
Ahmed bouchriha, modifié il y a 9 années.

RE: Custom user menu in theme

Junior Member Publications: 55 Date d'inscription: 04/05/12 Publications récentes
Hi Kousik,

You can achieve this by following the those steps :

1- Create a page custom field by adding the following code to your init_custom.vm

## ---------- usermenu Custom Field ---------- ##

#set ($userMenuCustomField = "user-navigation")

#if ($layout.getExpandoBridge().hasAttribute($userMenuCustomField) == false)
     #set($VOID = $layout.getExpandoBridge().addAttribute($userMenuCustomField, 1, false))
#end


2- Create a vm file under your theme templates folder called user-navigation.vm containing the following code :


<div id="user-navigation">
 
 <ul>
  #foreach ($nav_item in $nav_items)
                   #if($nav_item.getLayout().getExpandoBridge().getAttribute($userMenuCustomField))
   #if ($nav_item.isSelected())
    <li class="selected">
   #else
    </li><li>
   #end
    <a href="$nav_item.getURL()" $nav_item.gettarget()><span>$nav_item.icon() $nav_item.getName()</span></a>
 
   </li>
                    #end
  #end
 </ul>
</div>


3 - Include user-navigation.vm file in the portal_normal.vm (diffs/templates/portal_normal.vm)

#parse ("$full_templates_path/user-navigation.vm")


4- Set the custom field “userMenuCustomField” to true for the pages that you want them to appear on the user menu.


5- Set for the pages that you want them to appear on the user menu the suitable permission.


Best Regards
Kousik Majumder, modifié il y a 9 années.

RE: Custom user menu in theme

New Member Publications: 11 Date d'inscription: 04/04/13 Publications récentes
Thank you Olaf and Ahmed. Now this is working for me. But I do have a different problem now.

Now the menu is created and showing in Portlet 1 top right corner. Thereafter I wish to open a dialogue from the sub menu. When I am trying to do so it is showing error saying " You do not have the roles required to access this portlet".

And the reason is below url which is getting invoked when rendered from the main jsp in Portlet 2 while trying to open dialogue.

http://localhost:8080/homepage?p_p_id=My2ndPortlet_WAR_My2ndPortlet10SNAPSHOT&p_p_lifecycle=0&p_p_state=exclusive&p_p_mode=view&_My2ndPortlet_WAR_My2ndPortlet10SNAPSHOT_jspPage=%2Fjsp%2Fdialogue.jsp

What is the way out?

Note I have already added
<add-default-resource>true</add-default-resource>
in Portlet 2. Still not working.

Thanks in advance,
Kousik