Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Accessing Document Model from Javascript View modes: 
User avatar
Member
Member
Armysniper89 - 9/11/2011 4:48:04 PM
   
Accessing Document Model from Javascript
I have a very complex menu that needs to be displayed in my Kentico site. It would be easier to just leave the menu as is in HTML code and not have to fit it into a Kentico control. The problem I have is the ability to highlight the active top level menu item based on the current page in the site. I may be many levels deep in the site but I want to highlight the menu to show what section they are. This requires adding a "highlight" class to the main menu anchor tag. I could do it with some Jquery code but I have no way of knowing in my javascript code what document I am on. How can I access the document tree and more importantly the top level page of a section in Javascript?

User avatar
Member
Member
kentico_michal - 9/12/2011 1:09:34 AM
   
RE:Accessing Document Model from Javascript
Hello,

Regrettably, it is not possible to access the document tree using javascript.

However, you could use a hidden field to store any information that you need on the client side to decide which top level menu item should be highlighted. You can create a custom web part which could contain the simple hidden field:

<div class="hiddenFieldClass" >
<asp:HiddenField runat="server" ID="hiddenField" />
</div>


In the Page_Load handler, you can access it and set it to any value you need on the client side, for example:

hiddenField.Value = CMS.CMSHelper.CMSContext.CurrentPageInfo.DocumentName;

At this point you can place the web part on the master page so that it appears on each document and access the value of the hidden field using javascript. Based on the value, you can highlight appropriate menu item.

Best regards
Michal Legen

User avatar
Member
Member
Armysniper89 - 9/12/2011 12:09:26 PM
   
RE:Accessing Document Model from Javascript
I went to bed thinking about this idea last night. :) So my question would be how can I determine in code the parent document of a section? So for example if I have sections like this:

Section 1
Sub Content
Sub Content 2
Third Level Sub Content 1
Section 2

How can I have am on Third Level Sub Content 1 determine the value of the root parent (Section 1)?

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 9/12/2011 11:04:27 PM
   
RE:Accessing Document Model from Javascript
Hi,

you could for example parse alias path of current node:

/topParent/secondLevel/thirdLevel


From the above alias path you are able to determine alias path of the top parent:

/topParent

And finally using document API you can find information you are looking for.

Alternatively, if you need select nodes from appropriate level you can use SelectNodes method and define its where property, for example NodeLevel=1. This way only top level documents will be selected.

Best regards,
Ivana Tomanickova