Foren

Issue in detecting selected Nav Item in Menu using Ajax

thumbnail
Nithin KV, geändert vor 8 Jahren.

Issue in detecting selected Nav Item in Menu using Ajax

Junior Member Beiträge: 56 Beitrittsdatum: 23.07.12 Neueste Beiträge
Anyone has created a Menu portlet and embedded in the theme and rendered it in the theme using ajax ?..
I am facing issues in detecting a selected nav item using ajax after i render it !! Kindly help if you are aware
thumbnail
Julien Mourad, geändert vor 8 Jahren.

RE: Issue in detecting selected Nav Item in Menu using Ajax

Junior Member Beiträge: 78 Beitrittsdatum: 22.01.15 Neueste Beiträge
<nav id="site-navigation">
	<ul id="site-pages"></ul>
</nav>

<script type="text/javascript">
	AUI().use(
	'aui-node',
	function(A){
		Liferay.Service(
		'/layout/get-layouts',
		{
			groupId: Liferay.ThemeDisplay.getSiteGroupId(),
			privateLayout: false,
			parentLayoutId: 0
		},
		function(obj) {
			if(obj.length > 0){
				var nav = A.one("#site-pages"),
					result = "",
					selected = "";

				obj.forEach( function(entry){
					if(!entry.hidden){
						if( entry.layoutId == Liferay.ThemeDisplay.getLayoutId() ){
							selected = "selected active";
						}
						else{
							selected = "";
						}
						result += '<li><a href="'+ entry.friendlyURL +'" class="' + selected + '">' + entry.nameCurrentValue + '</a></li>';
					}
				});
				
				nav.setContent(result);
			}
		});
	});
</script>


You can also use the plid if you want, like so
if( entry.plid == Liferay.ThemeDisplay.getPlid() )

For parentLayoutId, the value 0 will start from the root. You could use
Liferay.ThemeDisplay.getLayoutId()
to display the child pages of the current page or
Liferay.ThemeDisplay.getParentLayoutId()
to start from the parent of the current page.
thumbnail
Nithin KV, geändert vor 7 Jahren.

RE: Issue in detecting selected Nav Item in Menu using Ajax

Junior Member Beiträge: 56 Beitrittsdatum: 23.07.12 Neueste Beiträge
THanks !