掲示板

Forcing navigation.vm to use default community nav_items

thumbnail
13年前 に Amit Aggarwal によって更新されました。

Forcing navigation.vm to use default community nav_items

Junior Member 投稿: 87 参加年月日: 10/08/20 最新の投稿
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
12年前 に Brian Scott Schupbach によって更新されました。

RE: Forcing navigation.vm to use default community nav_items

Expert 投稿: 329 参加年月日: 08/10/23 最新の投稿
Hello,

Did you ever get this figured out?

Thanks!

Brian
thumbnail
12年前 に Brian Scott Schupbach によって更新されました。

RE: Forcing navigation.vm to use default community nav_items

Expert 投稿: 329 参加年月日: 08/10/23 最新の投稿
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
11年前 に Daniele Davi' によって更新されました。

RE: Forcing navigation.vm to use default community nav_items

New Member 投稿: 2 参加年月日: 10/11/19 最新の投稿
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
11年前 に John Carter によって更新されました。

RE: Forcing navigation.vm to use default community nav_items

Junior Member 投稿: 53 参加年月日: 12/10/18 最新の投稿
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
11年前 に Daniele Davi' によって更新されました。

RE: Forcing navigation.vm to use default community nav_items

New Member 投稿: 2 参加年月日: 10/11/19 最新の投稿
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
11年前 に Brian Scott Schupbach によって更新されました。

RE: Forcing navigation.vm to use default community nav_items

Expert 投稿: 329 参加年月日: 08/10/23 最新の投稿
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>
11年前 に Magda Ozana によって更新されました。

RE: Forcing navigation.vm to use default community nav_items

New Member 投稿: 6 参加年月日: 10/06/23 最新の投稿
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