Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Darth Lord
Change $nav_items to display same dynamic menu across communities
9. Mai 2011 14:31
Antwort

Darth Lord

Rang: New Member

Nachrichten: 6

Eintrittsdatum: 21. Mai 2010

Neue Beiträge

Hi

I have this requirement where the I need to display the same menu from community A across all other community as the top menu.

I will try to elaborate here: The landing page is built as a community where all users have access.Once a user logs on the landing page; let's called this community A, a set of top navigations are displayed. The navigations are the community children pages and displayed on community A once logged in. There is a hardcoded menu which navigates the user to another community which the user is a member of; let's called this community B.

Based on Liferay logic, the top navigation for community B will be displayed (top pages of community B ) instead of the navigation which was available in community A. I am required to display only the navigation from community A regardless of the community the user is currently viewing. I have looked at navigation.vm, VelocityVariables.java and the theme but I just don't understand where to make the required changes.

I hope that someone can help with this issue as I have been hitting my head against the wall to figure this out. I hope someone can guide me to the right path.

Thanks in advance

Darth Lord
Anil Sunkari
RE: Change $nav_items to display same dynamic menu across communities
16. Mai 2011 02:01
Antwort

Anil Sunkari

Rang: Expert

Nachrichten: 385

Eintrittsdatum: 11. August 2009

Neue Beiträge

Darth Lord:
Hi

I have this requirement where the I need to display the same menu from community A across all other community as the top menu.

I will try to elaborate here: The landing page is built as a community where all users have access.Once a user logs on the landing page; let's called this community A, a set of top navigations are displayed. The navigations are the community children pages and displayed on community A once logged in. There is a hardcoded menu which navigates the user to another community which the user is a member of; let's called this community B.

Based on Liferay logic, the top navigation for community B will be displayed (top pages of community B ) instead of the navigation which was available in community A. I am required to display only the navigation from community A regardless of the community the user is currently viewing. I have looked at navigation.vm, VelocityVariables.java and the theme but I just don't understand where to make the required changes.

I hope that someone can help with this issue as I have been hitting my head against the wall to figure this out. I hope someone can guide me to the right path.

Thanks in advance

Darth Lord


Hi Darth Lord,

As i hope i have got your requirement understanding clearly.Here i'm re-explaining about your requirement.You need some set of navigation menus in every community where user enters.Is this right then you have to go with below specified solution.......

1) Create community with name called "OPEN_TEMPLATE","RESTRICTED_TEMPLATE","DEFAULT_TEMPLATE" according to your choice where all these three depends on type of community you are creating(open(OPEN_TEMPLATE),restricted(RESTRICTED_TEMPLATE),private).Where these templates explain you about writing once & creating every time.
2) I mean after creating this you have to make some configurations to work it perfectly.

Let me know if i'm giving you exact solution........so that i'll tell you further process to achive your goal.

Thanks
Anil Sunkari
Darth Lord
RE: Change $nav_items to display same dynamic menu across communities
17. Mai 2011 01:33
Antwort

Darth Lord

Rang: New Member

Nachrichten: 6

Eintrittsdatum: 21. Mai 2010

Neue Beiträge

Hi Anil,

I was able to fix using something similar that you suggested. I looked up the community group id and then retrieve is layout with ThemeDisplay. I then iterated through the layers by only storing private layout with "hidden == true" so that I did not get all private pages. I then stored the collection as the $nav_items. The changes can be made in two places:

1. ServicePreAction.java
2. VelocityVariables.java

do not make the changes in both place, either classes will work with the correct implementation.

Darth
Anil Sunkari
RE: Change $nav_items to display same dynamic menu across communities
18. Mai 2011 01:31
Antwort

Anil Sunkari

Rang: Expert

Nachrichten: 385

Eintrittsdatum: 11. August 2009

Neue Beiträge

Yes, Exactly you are right ! emoticon
Brian Scott Schupbach
RE: Change $nav_items to display same dynamic menu across communities
21. März 2012 07:00
Antwort

Brian Scott Schupbach

Rang: Expert

Nachrichten: 329

Eintrittsdatum: 23. Oktober 2008

Neue Beiträge

Can you post your code? I'm having the same issue.

Thanks!

Brian
Brian Scott Schupbach
RE: Change $nav_items to display same dynamic menu across communities
23. März 2012 11:53
Antwort

Brian Scott Schupbach

Rang: Expert

Nachrichten: 329

Eintrittsdatum: 23. Oktober 2008

Neue Beiträge

Here you go...this was written in liferay 6.1 CE GA1

 1   
 2
 3##set this to the groupID of the menu you wish to copy
 4#set ($mainGroupId = $getterUtil.getLong('11379'))               
 5              #set ($layoutService = $serviceLocator.findService('com.liferay.portal.service.ThemeLocalServiceBaseImpl'))
 6               
 7           #if ($page_group.groupId != $mainGroupId) ## The main site's groupId
 8                   #set ($layoutService = $serviceLocator.findService('com.liferay.portal.service.LayoutLocalService'))
 9                   #set ($mainLayoutPlid = $layoutService.getDefaultPlid($mainGroupId, true)) ##true for private pages and false for public
10                   #set ($mainLayout = $layoutService.getLayout($mainLayoutPlid))
11                   #set ($mainLayouts = $layoutService.getLayouts($mainGroupId, true,0))
12       
13                   ##Need to loop through and only display the the non hidden menu items   
14                   #set($newMainLayouts = [])
15                   #foreach ($newLayout in $mainLayouts)
16                        #if($newLayout.isHidden() == false)
17                            $newMainLayouts.add($newLayout)
18                        #end
19                   #end
20                   
21                   #set ($requestVarsClass = $portal.getClass().forName('com.liferay.portal.theme.RequestVars'))
22                   #set ($requestVarsConstructor = $requestVarsClass.constructors)
23                   #set ($requestVarsConstructor = $requestVarsConstructor.get(0))
24                   #set ($requestVars = $requestVarsConstructor.newInstance($request, $theme_display, $mainLayout.ancestorPlid, $mainLayout.ancestorLayoutId))
25                   #set ($navItemClass = $portal.getClass().forName('com.liferay.portal.theme.NavItem'))
26
27                   ##set ($newNavItems = $navItemClass.fromLayouts($requestVars, $mainLayouts))
28                   #set ($newNavItems = $navItemClass.fromLayouts($requestVars, $newMainLayouts))
29                   #set ($nav_items = $newNavItems)
30          #end
31
32<nav class="$nav_css_class" id="navigation">
33    <h1>
34        <span>#language("navigation")</span>
35    </h1>
36
37    <ul>
38        #foreach ($nav_item in $nav_items)
39            #if ($nav_item.isSelected())
40                <li class="selected">
41            #else
42                <li>
43            #end
44               
45                <a href="$nav_item.getURL()" $nav_item.getTarget()><span>$nav_item.icon() $nav_item.getName()</span></a>
46
47                #if ($nav_item.hasChildren())
48                    <ul class="child-menu">
49                        #foreach ($nav_child in $nav_item.getChildren())
50                            #if ($nav_child.isSelected())
51                                <li class="selected">
52                            #else
53                                <li>
54                            #end
55                                <a href="$nav_child.getURL()" $nav_child.getTarget()>$nav_child.getName()</a>
56                            </li>
57                        #end
58                    </ul>
59                #end
60            </li>
61        #end
62    </ul>
63</nav>
Reinaud van Rumpt
RE: Change $nav_items to display same dynamic menu across communities
12. März 2013 05:43
Antwort

Reinaud van Rumpt

Rang: New Member

Nachrichten: 2

Eintrittsdatum: 12. März 2013

Neue Beiträge

Hi Brian,

I'm trying your code, but I get the following error during visiting a page which is not the main group.

com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.liferay.portal.service.ThemeLocalServiceBaseImpl' is defined

Using liferay 6.1.1

Thanks in advance!
Brian Scott Schupbach
RE: Change $nav_items to display same dynamic menu across communities
12. März 2013 06:13
Antwort

Brian Scott Schupbach

Rang: Expert

Nachrichten: 329

Eintrittsdatum: 23. Oktober 2008

Neue Beiträge

what version are you using? Your error is saying it can't find the class name that is being referenced.

Here is what I'm using in 6.1 GA2

 1
 2#set ($mainGroupId = $getterUtil.getLong('11379'))
 3
 4#set ($layoutService = $serviceLocator.findService('com.liferay.portal.service.LayoutLocalService'))
 5#set ($mainLayoutPlid = $layoutService.getDefaultPlid($mainGroupId, true))
 6#set ($mainLayout = $layoutService.getLayout($mainLayoutPlid))
 7#set ($mainLayouts = $layoutService.getLayouts($mainGroupId, true,0))
 8
 9<nav class="$nav_css_class" id="navigation">
10        <h1><span>#language("navigation")</span></h1>
11        <ul>
12           #foreach ($newLayout in $mainLayouts)
13           #if($newLayout.isHidden() == false)
14                #if ($newLayout.isSelected())
15                    <li class="selected">
16                #else
17                    <li>
18                #end
19                    <a href="/group/my-group-name$newLayout.getFriendlyURL()" $newLayout.getTarget()><span>$newLayout.getName()</span></a>
20                    #if($is_signed_in)
21                        #if ($newLayout.hasChildren())
22                            <ul class="child-menu">
23                                #foreach ($nav_child in $newLayout.getChildren())
24                                #if ($nav_child.getHidden())
25                                                                        
26                                #else
27                                    #if ($nav_child.isSelected())
28                                        <li class="selected">
29                                    #else
30                                        <li>
31                                    #end
32                                        <a href="/group/my-group-name$nav_child.getFriendlyURL()" $nav_child.getTarget()>$nav_child.getName()</a>
33                                    </li>
34                                #end
35                                #end
36                            </ul>
37                        #end
38                    #end
39                </li>
40            #end
41            #end
42        </ul>
43</nav>