Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Amit Aggarwal
Forcing navigation.vm to use default community nav_items
19. Januar 2011 14:27
Antwort

Amit Aggarwal

Rang: Junior Member

Nachrichten: 87

Eintrittsdatum: 20. August 2010

Neue Beiträge

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.
Brian Scott Schupbach
RE: Forcing navigation.vm to use default community nav_items
21. März 2012 06:47
Antwort

Brian Scott Schupbach

Rang: Expert

Nachrichten: 329

Eintrittsdatum: 23. Oktober 2008

Neue Beiträge

Hello,

Did you ever get this figured out?

Thanks!

Brian
Brian Scott Schupbach
RE: Forcing navigation.vm to use default community nav_items
23. März 2012 11:54
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>
Daniele Davi'
RE: Forcing navigation.vm to use default community nav_items
25. Oktober 2012 02:43
Antwort

Daniele Davi'

Rang: New Member

Nachrichten: 2

Eintrittsdatum: 19. November 2010

Neue Beiträge

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
parikshit sharma
RE: Forcing navigation.vm to use default community nav_items
25. Oktober 2012 04:11
Antwort

parikshit sharma

Rang: Junior Member

Nachrichten: 47

Eintrittsdatum: 18. Oktober 2012

Neue Beiträge

Daniele,

I think you can use below code ,seems that it will work
1
2#set($velocityEngineUtil=$portal.getClass().forName('com.liferay.portal.kernel.velocity.VelocityEngineUtil'))
3#set($templateContext=$velocityEngineUtil.getWrappedStandardToolsContext())

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

1
2#set ($requestVars = $requestVarsConstructor.newInstance($request, $theme_display, $mainLayout.ancestorPlid, $mainLayout.ancestorLayoutId,$templateContext))
Daniele Davi'
RE: Forcing navigation.vm to use default community nav_items
25. Oktober 2012 06:03
Antwort

Daniele Davi'

Rang: New Member

Nachrichten: 2

Eintrittsdatum: 19. November 2010

Neue Beiträge

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)
Brian Scott Schupbach
RE: Forcing navigation.vm to use default community nav_items
25. Oktober 2012 06:08
Antwort

Brian Scott Schupbach

Rang: Expert

Nachrichten: 329

Eintrittsdatum: 23. Oktober 2008

Neue Beiträge

Try this:

 1
 2##change to the groupID you wish to copy
 3#set ($mainGroupId = $getterUtil.getLong('11379'))
 4
 5#set ($layoutService = $serviceLocator.findService('com.liferay.portal.service.LayoutLocalService'))
 6#set ($mainLayoutPlid = $layoutService.getDefaultPlid($mainGroupId, true))
 7#set ($mainLayout = $layoutService.getLayout($mainLayoutPlid))
 8#set ($mainLayouts = $layoutService.getLayouts($mainGroupId, true,0))
 9
10<nav class="$nav_css_class" id="navigation">
11        <h1><span>#language("navigation")</span></h1>
12        <ul>
13           #foreach ($newLayout in $mainLayouts)
14           #if($newLayout.isHidden() == false)
15                #if ($newLayout.isSelected())
16                    <li class="selected">
17                #else
18                    <li>
19                #end
20                    <a href="/group/nu-foundation$newLayout.getFriendlyURL()" $newLayout.getTarget()><span>$newLayout.getName()</span></a>
21                    #if($is_signed_in)
22                        #if ($newLayout.hasChildren())
23                            <ul class="child-menu">
24                                #foreach ($nav_child in $newLayout.getChildren())
25                                    #if ($nav_child.isSelected())
26                                        <li class="selected">
27                                    #else
28                                        <li>
29                                    #end
30                                        <a href="/group/nu-foundation$nav_child.getFriendlyURL()" $nav_child.getTarget()>$nav_child.getName()</a>
31                                    </li>
32                                #end
33                            </ul>
34                        #end
35                    #end
36                </li>
37            #end
38            #end
39        </ul>
40</nav>
Magda Ozana
RE: Forcing navigation.vm to use default community nav_items
9. November 2012 07:19
Antwort

Magda Ozana

Rang: New Member

Nachrichten: 6

Eintrittsdatum: 23. Juni 2010

Neue Beiträge

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