Wednesday, February 6, 2008

Brazilian Wax Mobile Al

xslt entity for the dynamic menu rujoch.it

few weeks ago (too many), Simone, a reader of the blog, asked me if I could explain how I created the menu www.rujoch.it dynamic site.

Here's the answer:


Javascript


As you would guess, the basis of this menu is simply a javascript, downloaded from the excellent Dynamic Drive. The script is called AnyLink Drop Down Menu and the code can be found on this page: http://www.dynamicdrive.com/dynamicindex1/dropmenuindex.htm


For simplicity, I moved the javascript code on the outside and, Site created with umbraco, I'll call him in the head section of a template with the call:


\u0026lt;script language="JavaScript" type="text/javascript" src="/menuSup.aspx"> \u0026lt;/ script> ;


You read that right: the javascript will become a file. aspx, it has to be generated dynamically.


As you can see from the code visible on Dynamic Drive, for each menu item, there is a call two functions in the javascript file. This part (the entire menu), my website with umbraco, it becomes dynamic.


Navigation


On a site built with umbraco, the major difficulty is to select nodes umbraco.config file that you wish to speak. For the menu, it would seem very simple because the structure of the site is that the user interface is built in the contents pane. Suffice then decide how many levels you want display. (An XSLT files with this feature is installed with the version 3 of umbraco, see section developper interface).


umbraco you start getting to grips with, however, to include in the tree of content that should never be represented as an HTML page (an RSS feed, javascript dynamic, etc.).. Moreover, not all the pages of a particular "node" should always end up in the menu.


Following the method suggested by Warren Buckley, you can then provide all kinds of documents (Dokumenttyper) of a field of type boolean might be called IsVisible. In this way, I can select the nodes that have an attribute IsVisible equal to 1.


for Xslt Xslt


menu for the menu page (the part included between the tag and \u0026lt;ul id="menu"> \u0026lt;/ ul>) www.rujoch.it site for inclusion in the master template common to all pages. (Command post macro)


omits all the header of the xml file, which provides in its umbraco xslt template files and the content shown below should be adapted and inserted after the \u0026lt;! - Start writing XSLT -> ;


\u0026lt;ul id="menu">

\u0026lt;xsl:for-each select="$currentPage/ancestor::root/*/node[@level='2']">

\u0026lt;! - Translation: wherever I may, return to the root of the xml file and select the nodes that are called nodes and have an attribute level equal to 2 (in practice, in the content, are the first branches ) and for each of them (for-each statement) executes the following statement ->

\u0026lt;!--====================== ================================================== =============-->

\u0026lt;xsl:variable name="posizione">

\u0026lt;xsl: value-of select = "position () -1" / >

\u0026lt;/ xsl: variable>

\u0026lt;! - I needed a xslt variable that returns the position of the selected node in the array of selected nodes; arrays in javascript in xslt and are treated differently: the first javascript element has index 0, 1 xslt. The variable is defined here before they can be used. ->

\u0026lt;xsl:if test="./data[@alias='isVisible']=1">

\u0026lt;! - If you've specified using the boolean above that the item should I write to be visible in the file generated on the fly: ->

\u0026lt;li>

\u0026lt;a href = "#" onclick = "return clickreturnvalue, () location.href = '{umbraco.library: NiceUrl (@ id)}'" onmouseover = "DropDownMenu (this, event, menu} {$ position, '100px ')" onmouseout = "delayhidemenu ()">\u0026lt; xsl: value-of select = "@ nodeName "/>\u0026lt;/ a> \u0026lt;/ li>

\u0026lt;/ xsl: if>

\u0026lt;! - This part is Only the call to the javascript for each link, I put in a url dynamically, a number that corresponds to the position of the menu item and a display name in the menu ->

\u0026lt;!--===== ================================================== =====================================-->

\u0026lt;/ xsl: for-each>

\u0026lt;/ ul>

located in the template, this macro writes the following code:


\u0026lt;ul id="menu"> \u0026lt;li> \u0026lt; a href = "#" onclick = "return clickreturnvalue, () location.href = '/ sci-club.aspx'" onmouseover = "DropDownMenu (this, event, menu1, '100px ')" onmouseout = "delayhidemenu ()" > Ski Club \u0026lt;/ a> \u0026lt;/ li> [I have used since the instruction xsl: for-each, followed by all other menu items ... and finally, the tag that closes the unordered list] \u0026lt; / ul>


Il javascript "dinamico"


Abbiamo ora una pagina che chiama un javascript e si aspetta di trovarci degli array.
Ci resta da scrivere il javascript. (Controllare eventualmente il codice javascript su Dynamic Drive, per capire come deve risultare il javascript.)


La logica รจ la stessa ma le istruzioni xsl:for-each da utilizzare sono due, l'una all'interno dell'altra.

La parte di xslt restituisce semplicemente tutti gli array del javascript.


<xsl:for-each select="$currentPage/ancestor::root/*/node[@level='2']">

<!--=====================================================================================-->

\u0026lt;xsl:variable name="posizione">

\u0026lt;xsl:value-of select="position()-1"/>

\u0026lt;/ xsl: variable>

\u0026lt;xsl: if test = ". / data [@ alias = 'IsVisible'] = 1">

\u0026lt;xsl:value-of select="position()-1"/> var menu = new Array ()

\u0026lt; ; xsl: for-each select = "node [@ level = '3 'and string (data [@ alias =' IsVisible ']) = '1']">

menu \u0026lt;xsl: value-of select = " $ position "/>[\u0026lt; xsl: value-of select = "position () -1 to "/>]='\u0026lt; href = "{umbraco.library: NiceUrl (@ id )}">\u0026lt; xsl: value-of select =" @ nodeName "/>\u0026lt;/ a> '

\u0026lt;/ xsl: for-each>

\u0026lt;/ xsl: if>

The result (in part) will be:


var menu1 = new Array ()

menu1 [0] = '\u0026lt;a href = "/ sci-club/tesseramento.aspx "> Membership \u0026lt;/ a> 'menu1

[1] =' \u0026lt;a href="/sci-club/vantaggi.aspx"> Benefits \u0026lt;/ a> '

menu1 [2] =' \u0026lt; a href = "/ sci-club/direttivo.aspx"> Executive \u0026lt;/ a> '

not enough because this is only part of the array. I have to write everything else.

Creo therefore a type of document (Dokumenttyper) named javascript and its template. Tab info on the type of document, the only authorized must be that corresponding template (it's called if I have javascript enabled umbraco for me to create it, by checking the Create matching template to create the type of document). Look no further. I must not define any "tab" and no property! The template for


javascript:


template editor, type:

/ / <! [CDATA [

/**************** *******************************

AnyLink * Drop Down Menu-© Dynamic Drive (www.dynamicdrive.com)

* This notice MUST stay intact for legal use * Visit

http://www.dynamicdrive.com/ for full source code

* **********************************************/

in Then, enter the xslt macro you created earlier.


following javascript code located below the array (do not write it, you can just cut paste from the site of Dynamic Drive)

and IMPORTANT , close the CDATA section that contains the javascript typing


/ /]] >


It 's done! enough for you now create in the content section of umbraco interface based on a template file and call javascript menuSup (or in the way you decide to call your external javascript). I then called up from the head, as previously indicated.

0 comments:

Post a Comment