Fórumok
Problems detecting a selected nav item in velocity template
E S, módosítva 13 év-val korábban
Problems detecting a selected nav item in velocity template
Junior Member Bejegyzések: 38 Csatlakozás dátuma: 2010.04.21. Legújabb bejegyzések
I am having a problem in my navigation.vm template. Here is the code for the site's navigation:
For some reason, none of my navigation items on the site ever get the "selected" class assigned to it. I am having a lot of trouble figuring out why. Can anyone see a problem with my template?
<ul>
#foreach ($nav_item in $nav_items)
#if ($nav_item.isSelected())
#set ($nav_item_class = "selected")
<b>Selected!</b>
#else
#set ($nav_item_class = "")
#end
#if ($nav_item.getName() != "Home")
<li class="$nav_item_class">
<a href="$nav_item.getURL()" $nav_item.gettarget()><span>$nav_item.getName()</span></a>
</li>
#end
#end
</ul>
For some reason, none of my navigation items on the site ever get the "selected" class assigned to it. I am having a lot of trouble figuring out why. Can anyone see a problem with my template?
Robert Kornmesser, módosítva 12 év-val korábban
RE: Problems detecting a selected nav item in velocity template
Junior Member Bejegyzések: 39 Csatlakozás dátuma: 2011.11.03. Legújabb bejegyzések
Same problem here!
In portal_normal.vm, i include navigation 2 times. First time isSelected(() works as desired. second time not.
WHY?
In portal_normal.vm, i include navigation 2 times. First time isSelected(() works as desired. second time not.
WHY?
Bradley Wood, módosítva 11 év-val korábban
RE: Problems detecting a selected nav item in velocity template
Mason Stein, módosítva 11 év-val korábban
RE: Problems detecting a selected nav item in velocity template
Junior Member Bejegyzések: 47 Csatlakozás dátuma: 2012.12.05. Legújabb bejegyzések
Hey,
strange..I have the same problem.
When I visit the public site my li elements never get the selected class. When I login , everything is fine ?!?
Any help?
strange..I have the same problem.
When I visit the public site my li elements never get the selected class. When I login , everything is fine ?!?
#foreach ($nav_item in $nav_items)
#if ($nav_item.isSelected())
<li class="selected">
#else
</li>
#end
Any help?
Michal Sima, módosítva 10 év-val korábban
RE: Problems detecting a selected nav item in velocity template
New Member Bejegyzések: 24 Csatlakozás dátuma: 2013.02.27. Legújabb bejegyzések
Did you solve it?
James charley, módosítva 10 év-val korábban
RE: Problems detecting a selected nav item in velocity template
Junior Member Bejegyzések: 44 Csatlakozás dátuma: 2013.06.12. Legújabb bejegyzések
Any one solved the above issue ?
Aldi Tirane, módosítva 10 év-val korábban
RE: Problems detecting a selected nav item in velocity template
Junior Member Bejegyzések: 25 Csatlakozás dátuma: 2012.10.23. Legújabb bejegyzések
Hello to everyone.
Did anybody solve this issue?
Thanks.
Did anybody solve this issue?
Thanks.
Mason Stein:
Hey,
strange..I have the same problem.
When I visit the public site my li elements never get the selected class. When I login , everything is fine ?!?#foreach ($nav_item in $nav_items) #if ($nav_item.isSelected()) <li class="selected"> #else </li>
#end
Any help?
Laxman Rana, módosítva 10 év-val korábban
RE: Problems detecting a selected nav item in velocity template
New Member Bejegyzések: 23 Csatlakozás dátuma: 2013.07.15. Legújabb bejegyzések
Hi,
Try with this code
Thanks,
Laxman Rana
Surekha Technologies
www.surekhatech.com
Try with this code
<nav class="$nav_css_class" id="nav_menu">
<ul class="nav">
#foreach ($nav_item in $nav_items)
#if ($nav_item.isSelected())
<li class="selected active">
#else
</li><li>
#end
</li></ul>
</nav>
Thanks,
Laxman Rana
Surekha Technologies
www.surekhatech.com
Aldi Tirane, módosítva 10 év-val korábban
RE: Problems detecting a selected nav item in velocity template
Junior Member Bejegyzések: 25 Csatlakozás dátuma: 2012.10.23. Legújabb bejegyzések
The problem is that $nav_item.isSelected() return always false.
I found why this happens. I have included in header.vm the sign-in portlet with the following code:
If i remove this code in the header the $nav_item.isSelected() behaves normally returning true for the page where the user is in.
I don't know why this happens, maybe someone can give a more detailed explanation.
Thanks, Aldi.
I found why this happens. I have included in header.vm the sign-in portlet with the following code:
#set ($locPortletId = "58")
$velocityPortletPreferences.setValue("portlet-setup-show-borders","false")
#set($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString()))
$locRenderedPortletContent
$velocityPortletPreferences.reset()
If i remove this code in the header the $nav_item.isSelected() behaves normally returning true for the page where the user is in.
I don't know why this happens, maybe someone can give a more detailed explanation.
Thanks, Aldi.
Puneet Malode, módosítva 10 év-val korábban
RE: Problems detecting a selected nav item in velocity template
New Member Bejegyzések: 17 Csatlakozás dátuma: 2012.07.20. Legújabb bejegyzések
Hi,
I have created the portlet to access Navigation. But I am not able to get the selected NavItem. Please help me to solve this problem.
Please find the below code for your reference.
In my Portlet Controller class.
In my JSP
I have created the portlet to access Navigation. But I am not able to get the selected NavItem. Please help me to solve this problem.
Please find the below code for your reference.
In my Portlet Controller class.
public String getChildPages(RenderRequest request, RenderResponse response, ExtendedModelMap model){
try {
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
List<layout> layouts = themeDisplay.getLayouts();
Layout layout = themeDisplay.getLayout();
HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(request);
for (Layout lay : layouts) {
System.out.println("Is Layout Selected ? "+lay.isSelected(true, lay, lay.getAncestorPlid()));
System.out.println("Is Child Selected ? "+lay.isChildSelected(true, lay));
}
VelocityContext velocityContext = VelocityEngineUtil.getWrappedStandardToolsContext();
RequestVars requestVars = new RequestVars(httpServletRequest, themeDisplay, layout.getAncestorPlid(), layout.getAncestorLayoutId(), velocityContext);
List<navitem> navItems = NavItem.fromLayouts(requestVars, layouts);
for (NavItem navItem : navItems) {
System.out.println("NavItem Selected ? "+navItem.isSelected());
System.out.println("Is Child Selected ? "+navItem.isChildSelected());
}
model.put("NavItems", navItems);
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
return "LeftNav";
}
</navitem></layout>
In my JSP
<ul class="list-group">
<c:foreach items="${NavItems}" var="navItem">
<c:if test="${navItem.hasChildren()}">
<c:if test="${navItem.isChildSelected()}">
<c:foreach items="${navItem.getChildren()}" var="child1">
<c:if test="${child1.isSelected()}">
<li class="list-group-item current">
<c:if test="${!child1.isSelected()}">
</c:if></li><li class="list-group-item">
<a href="${child1.getURL() }">
${child1.getName() }
</a>
</li>
</c:if></c:foreach>
</c:if>
</c:if>
</c:foreach>
</ul>
Dominique Ebert, módosítva 9 év-val korábban
RE: Problems detecting a selected nav item in velocity template
Junior Member Bejegyzések: 29 Csatlakozás dátuma: 2013.02.01. Legújabb bejegyzések
Hi everybody,
I know the thread is a little bit old but I found a workaround for the problem someone mentioned in here and I thought it would be better to post it here instead of creating a new thread. I faced the same problem as Aldi Tirane did (see quote). I embedded a Portlet into my theme with the liferay suggested code (see quote again ;) ). But whenever i did that, the isSelected() Function always returned false.
So I tried to embedd the portlet after the navigation was built and that worked. So I came up with this workaround, maybe its useful to somebody with the same issue:
- My navigation code was stored in the navigation.vm so I parsed the content of the navigation into a variable:
This made sure the navigation had been created before I embedded the portlet. Afterwards I embedded the portlet as suggested in the quote. Afterwards I just printed the content of the variable where I wanted the navigation to appear.
That worked fine for me, I hope this may be useful to somebody.
Last but not least - does anybody know why this problem occurs in the first place, or wether it has been resolved after 6.1GA2?
Regards
I know the thread is a little bit old but I found a workaround for the problem someone mentioned in here and I thought it would be better to post it here instead of creating a new thread. I faced the same problem as Aldi Tirane did (see quote). I embedded a Portlet into my theme with the liferay suggested code (see quote again ;) ). But whenever i did that, the isSelected() Function always returned false.
So I tried to embedd the portlet after the navigation was built and that worked. So I came up with this workaround, maybe its useful to somebody with the same issue:
- My navigation code was stored in the navigation.vm so I parsed the content of the navigation into a variable:
#set($navigationPath = "$full_templates_path/navigation.vm")
#set ($navigationParsed="#parse($navigationPath )")
This made sure the navigation had been created before I embedded the portlet. Afterwards I embedded the portlet as suggested in the quote. Afterwards I just printed the content of the variable where I wanted the navigation to appear.
That worked fine for me, I hope this may be useful to somebody.
Last but not least - does anybody know why this problem occurs in the first place, or wether it has been resolved after 6.1GA2?
Regards
Aldi Tirane:
The problem is that $nav_item.isSelected() return always false.
I found why this happens. I have included in header.vm the sign-in portlet with the following code:#set ($locPortletId = "58") $velocityPortletPreferences.setValue("portlet-setup-show-borders","false") #set($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString())) $locRenderedPortletContent $velocityPortletPreferences.reset()
If i remove this code in the header the $nav_item.isSelected() behaves normally returning true for the page where the user is in.
I don't know why this happens, maybe someone can give a more detailed explanation.
Thanks, Aldi.