Foren

Change $nav_items to display same dynamic menu across communities

thumbnail
Darth Lord, geändert vor 12 Jahren.

Change $nav_items to display same dynamic menu across communities

New Member Beiträge: 8 Beitrittsdatum: 21.05.10 Neueste 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
thumbnail
Anil Sunkari, geändert vor 12 Jahren.

RE: Change $nav_items to display same dynamic menu across communities

Expert Beiträge: 427 Beitrittsdatum: 12.08.09 Neueste 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
thumbnail
Darth Lord, geändert vor 12 Jahren.

RE: Change $nav_items to display same dynamic menu across communities

New Member Beiträge: 8 Beitrittsdatum: 21.05.10 Neueste 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
thumbnail
Anil Sunkari, geändert vor 12 Jahren.

RE: Change $nav_items to display same dynamic menu across communities

Expert Beiträge: 427 Beitrittsdatum: 12.08.09 Neueste Beiträge
Yes, Exactly you are right ! emoticon
thumbnail
Brian Scott Schupbach, geändert vor 12 Jahren.

RE: Change $nav_items to display same dynamic menu across communities

Expert Beiträge: 329 Beitrittsdatum: 23.10.08 Neueste Beiträge
Can you post your code? I'm having the same issue.

Thanks!

Brian
thumbnail
Brian Scott Schupbach, geändert vor 12 Jahren.

RE: Change $nav_items to display same dynamic menu across communities

Expert Beiträge: 329 Beitrittsdatum: 23.10.08 Neueste Beiträge
Here you go...this was written in liferay 6.1 CE GA1

   

##set this to the groupID of the menu you wish to copy
#set ($mainGroupId = $getterUtil.getLong('11379'))   			
   		   #set ($layoutService = $serviceLocator.findService('com.liferay.portal.service.ThemeLocalServiceBaseImpl'))
   			
           #if ($page_group.groupId != $mainGroupId) ## The main site's groupId
                   #set ($layoutService = $serviceLocator.findService('com.liferay.portal.service.LayoutLocalService'))
                   #set ($mainLayoutPlid = $layoutService.getDefaultPlid($mainGroupId, true)) ##true for private pages and false for public
                   #set ($mainLayout = $layoutService.getLayout($mainLayoutPlid))
                   #set ($mainLayouts = $layoutService.getLayouts($mainGroupId, true,0))
        
        		   ##Need to loop through and only display the the non hidden menu items	
        		   #set($newMainLayouts = [])
			       #foreach ($newLayout in $mainLayouts)
			        	#if($newLayout.isHidden() == false)
			        		$newMainLayouts.add($newLayout)
			        	#end
			       #end
					
                   #set ($requestVarsClass = $portal.getClass().forName('com.liferay.portal.theme.RequestVars'))
                   #set ($requestVarsConstructor = $requestVarsClass.constructors)
                   #set ($requestVarsConstructor = $requestVarsConstructor.get(0))
                   #set ($requestVars = $requestVarsConstructor.newInstance($request, $theme_display, $mainLayout.ancestorPlid, $mainLayout.ancestorLayoutId))
                   #set ($navItemClass = $portal.getClass().forName('com.liferay.portal.theme.NavItem'))

                   ##set ($newNavItems = $navItemClass.fromLayouts($requestVars, $mainLayouts))
                   #set ($newNavItems = $navItemClass.fromLayouts($requestVars, $newMainLayouts))
                   #set ($nav_items = $newNavItems)
          #end

<nav class="$nav_css_class" id="navigation">
	<h1>
		<span>#language("navigation")</span>
	</h1>

	<ul>
		#foreach ($nav_item in $nav_items)
			#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>

				#if ($nav_item.hasChildren())
					<ul class="child-menu">
						#foreach ($nav_child in $nav_item.getChildren())
							#if ($nav_child.isSelected())
								<li class="selected">
							#else
								</li><li>
							#end
								<a href="$nav_child.getURL()" $nav_child.gettarget()>$nav_child.getName()</a>
							</li>
						#end
					</ul>
				#end
			</li>
		#end
	</ul>
</nav>

Reinaud van Rumpt, geändert vor 11 Jahren.

RE: Change $nav_items to display same dynamic menu across communities

New Member Beiträge: 2 Beitrittsdatum: 12.03.13 Neueste 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!
thumbnail
Brian Scott Schupbach, geändert vor 11 Jahren.

RE: Change $nav_items to display same dynamic menu across communities

Expert Beiträge: 329 Beitrittsdatum: 23.10.08 Neueste 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


#set ($mainGroupId = $getterUtil.getLong('11379'))

#set ($layoutService = $serviceLocator.findService('com.liferay.portal.service.LayoutLocalService'))
#set ($mainLayoutPlid = $layoutService.getDefaultPlid($mainGroupId, true))
#set ($mainLayout = $layoutService.getLayout($mainLayoutPlid))
#set ($mainLayouts = $layoutService.getLayouts($mainGroupId, true,0))

<nav class="$nav_css_class" id="navigation">
		<h1><span>#language("navigation")</span></h1>
		<ul>
		   #foreach ($newLayout in $mainLayouts)
    	   #if($newLayout.isHidden() == false)
				#if ($newLayout.isSelected())
					<li class="selected">
				#else
					</li><li>
				#end
					<a href="/group/my-group-name$newLayout.getFriendlyURL()" $newlayout.gettarget()><span>$newLayout.getName()</span></a>
					#if($is_signed_in)
						#if ($newLayout.hasChildren())
							<ul class="child-menu">
								#foreach ($nav_child in $newLayout.getChildren())
								#if ($nav_child.getHidden())
																		 
								#else
									#if ($nav_child.isSelected())
										<li class="selected">
									#else
										</li><li>
									#end
										<a href="/group/my-group-name$nav_child.getFriendlyURL()" $nav_child.gettarget()>$nav_child.getName()</a>
									</li>
								#end
								#end
							</ul>
						#end
					#end
				</li>
			#end
			#end
		</ul>
</nav>