Foros de discusión

Forcing navigation.vm to use default community nav_items

thumbnail
Amit Aggarwal, modificado hace 13 años.

Forcing navigation.vm to use default community nav_items

Junior Member Mensajes: 87 Fecha de incorporación: 20/08/10 Mensajes recientes
Hi, I got my navigation working great for my default community. Now, when I create a new community, the navigation gets completely replaced by the page structure in that community. I was wondering if there is a way to force the community-id (or whatever variable) so that the navigation.vm always puts the global nav on top? then I can add subnavigation for the specific community.
thumbnail
Brian Scott Schupbach, modificado hace 12 años.

RE: Forcing navigation.vm to use default community nav_items

Expert Mensajes: 329 Fecha de incorporación: 23/10/08 Mensajes recientes
Hello,

Did you ever get this figured out?

Thanks!

Brian
thumbnail
Brian Scott Schupbach, modificado hace 12 años.

RE: Forcing navigation.vm to use default community nav_items

Expert Mensajes: 329 Fecha de incorporación: 23/10/08 Mensajes recientes
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>

thumbnail
Daniele Davi', modificado hace 11 años.

RE: Forcing navigation.vm to use default community nav_items

New Member Mensajes: 2 Fecha de incorporación: 19/11/10 Mensajes recientes
Thanks Brian for youre code, it was very useful to our team.

Unfortunately it is not working on Liferay 6.1.1 GA2.
This is because in the new version they changed the com.liferay.portal.theme.RequestVars constructor: it now requires the VelocityContext as a parameter.
I was unable to retrive it from navigation.vm.

Did someone figured out how to make it work?

Thanks in advance
Daniele
John Carter, modificado hace 11 años.

RE: Forcing navigation.vm to use default community nav_items

Junior Member Mensajes: 53 Fecha de incorporación: 18/10/12 Mensajes recientes
Daniele,

I think you can use below code ,seems that it will work

#set($velocityEngineUtil=$portal.getClass().forName('com.liferay.portal.kernel.velocity.VelocityEngineUtil'))
#set($templateContext=$velocityEngineUtil.getWrappedStandardToolsContext())

before using $template ,please also verify the other arguments are available or not


#set ($requestVars = $requestVarsConstructor.newInstance($request, $theme_display, $mainLayout.ancestorPlid, $mainLayout.ancestorLayoutId,$templateContext))
thumbnail
Daniele Davi', modificado hace 11 años.

RE: Forcing navigation.vm to use default community nav_items

New Member Mensajes: 2 Fecha de incorporación: 19/11/10 Mensajes recientes
HI John,
thanks a million for you quick answer.
I tried your solution but it did not match my needs: it seems like the method 'velocityEngineUtil.getWrappedStandardToolsContext()' returns a sort of an empty context.

When calling $nav_item.icon() I get the following exception
12:57:13,942 ERROR [http-bio-8080-exec-10][LiferayMethodExceptionEventHandler:33] java.lang.NullPointerException
java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.liferay.portal.theme.NavItem.icon(NavItem.java:144)
at sun.reflect.GeneratedMethodAccessor462.invoke(Unknown Source)
......


It looks like the WrappedStandardToolsContext does not set "velocityTaglib#layoutIcon"
(see com.liferay.portal.theme.NavItem.java:144)
thumbnail
Brian Scott Schupbach, modificado hace 11 años.

RE: Forcing navigation.vm to use default community nav_items

Expert Mensajes: 329 Fecha de incorporación: 23/10/08 Mensajes recientes
Try this:


##change to the groupID you wish to copy
#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/nu-foundation$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.isSelected())
										<li class="selected">
									#else
										</li><li>
									#end
										<a href="/group/nu-foundation$nav_child.getFriendlyURL()" $nav_child.gettarget()>$nav_child.getName()</a>
									</li>
								#end
							</ul>
						#end
					#end
				</li>
			#end
			#end
		</ul>
</nav>
Magda Ozana, modificado hace 11 años.

RE: Forcing navigation.vm to use default community nav_items

New Member Mensajes: 6 Fecha de incorporación: 23/06/10 Mensajes recientes
I have the same problem with liferay version 6.1.1ga2 ,anyway it is working if i don't use $nav_item.icon(),but i want to use it !
Any solution for this?
Thx,
Magda