Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Frederik T 241 posts 372 karma points
    Aug 23, 2011 @ 15:47
    Frederik T
    0

    Help with site main menu, referencing directly to a node instead of currentPage

    The site im working on, has a main menu at the top a "mega menu" as the designers here call it. Its on every page and ever present.

    It shows the main section of the site, and when the cursor hovers over it shows a dropdown menu that contains some content from that section, like newest articles, links sub-sections etc.

    -Main
    ---Section 1
    -----blabla
    -----blabla
    ---Section 2
    -----blabla

    I can get content from it, so its wired up and working. Except for one thing, and that is the xpath (i guess).

    Right now, it looks for the descendants of currentPage, so if you are on say Section 1, you cant get any content from the menu that links to Section 2 and vice versa.
    And when you get further down some content vanishes, obviously because its looking for descendants.

    I know that currentpage is wrong, but that was the only solution i know if right now. I hope you understand my problem, if there is any questions please ask.

  • Rich Green 2246 posts 4008 karma points
    Aug 23, 2011 @ 15:56
    Rich Green
    0

    Hey,

    I would create a new XSLT file and base it on the 'SiteMap' template, have a look at how this works.

    You're right in that currentPage isn't too helpful in this case (apart from highlighting the item of nav you're on).

    What you need to do is always base the navigation from a fixed node (in this case the homepage / main node) or the root of the site, in effect the mark up should stay the same regardless of where you are in the site.

    Hope that helps.

    Rich

     

  • Frederik T 241 posts 372 karma points
    Aug 23, 2011 @ 16:15
    Frederik T
    0

    Thank you for your reply, yeah, thats exactly what i want it to do. I took at look at the default sitemap, either i dont know enough to understand it, or it isnt really what i need, sort of.

    Its not just navigation, it also displays content.

    The menu is like these

    http://designm.ag/inspiration/mega-menus/

    With the exception that mine has macros that displays latest articles in that section etc. And it has to stay the same regardless of page a user is viewing.

    I will keep fiddling with the default site map, but for good measure, how do i select the main node? Or is there another clever method?

  • Rich Green 2246 posts 4008 karma points
    Aug 23, 2011 @ 16:41
    Rich Green
    1

    Hi,

    Maybe have a look at the XSLT template that is called 'List Sub pages from a changeable source' then change the following line

    umbraco.library:GetXmlNodeById($source)

    to something like

    umbraco.library:GetXmlNodeById(1129)

    (change 1129 for whatever your home node is) see what this renders, and then have a play with the XSLT to also list the 3rd level.

    (You don't really need to hard code the home node, but it'll get you started.)

    Rich

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Aug 23, 2011 @ 21:06
    Chriztian Steinmeier
    2

    Hi Frederik,

    My default XSLT setup always creates a siteRoot variable just after the currentPage:

    <xsl:param name="currentPage" />
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />

    I then use that variable to select whatever is needed when it's not really related to currentPage, e.g.:

    <!-- Main navigation -->
    <xsl:apply-templates select="$siteRoot/Textpage[not(umbracoNaviHide = 1)]" />

     

    /Chriztian

  • Frederik T 241 posts 372 karma points
    Aug 26, 2011 @ 09:25
    Frederik T
    0

    Thank you! So i did a combination of both of your solutions, and it works greatly, except for one error.

    Before, when i used currentPage, it obviously only showed items for that section i was looking at, but when i was at the root main page, it only showed ONE item on the list, when i looked at that particular section, it showed all items on the list as it should. Which was odd but i didnt think much about since i knew it didnt work correctly.

    But now i used your advice, and it does show the correct items regardless what page im looking at BUT it only shows ONE item. Very odd indeed.

     

    <xsl:param name="currentPage"/>
    <xsl:variable name="siteRoot" select="umbraco.library:GetXmlNodeById(1065)" />

    <xsl:param name="maxItems" select="macro/maxItems"/>

    <xsl:template match="/">
      <ul class="list mm-list blue">
        <!-- Process ALL descendants of $currentPage -->
        <xsl:for-each select="$siteRoot/descendant::*[@isDoc][not(umbracoNaviHide = 1)]">
          <xsl:sort select="articleDate[normalize-space()]" order="descending" />
          <xsl:sort select="@updateDate[not(normalize-space(../articleDate))]" order="descending" />
          <xsl:if test="position() &lt;= $maxItems">
            <xsl:apply-templates select="." />
          </xsl:if>
        </xsl:for-each>
      </ul>
    </xsl:template>

    <!-- Template for specific DocumentTypes -->
    <xsl:template match="thisISaLotOfDocumentTypesInThisMatch | documentType1 | documentType2| etcetcetc">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <!-- Take first image (if any) -->
          <xsl:apply-templates select="outputPictures[1]" />
          <!-- Article heading and teaser text-->
          <h5><xsl:value-of select="articleHeading"/></h5>
          <!-- <p class="teaser"><xsl:value-of select="umbraco.library:TruncateString(artikel-Teasertekst,40,'...')"/></p> -->
        </a>
      </li>
    </xsl:template>

    <!-- Template for thumbnail image -->
    <xsl:template match="outputPictures">
      <img src="/ImageGen.ashx?image={DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&amp;width=70&amp;height=50" width="70" height="50" />
    </xsl:template>

    <!-- Template for all non-matched DocumentTypes -->
    <xsl:template match="*[@isDoc]" priority="-1">
            <!-- Suppress output... -->
    </xsl:template>

    </xsl:stylesheet>

     

  • Frederik T 241 posts 372 karma points
    Aug 29, 2011 @ 09:34
    Frederik T
    0

    Sorry for bumping, but i really need some advice.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Aug 29, 2011 @ 11:20
    Chriztian Steinmeier
    1

    Hi Frederik,

    It's hard to completely say what's wrong, but the only thing (in the code above) that would limit the output (excluding the $maxItems parameter which I assume is OK) would be if you're not matching the right DocumentTypes - it seems you're including plenty more than you're excluding, so you should maybe flip the logic, to easier see if you're missing some:

    <!-- Template for DocumentTypes to display -->
    <xsl:template match="*[@isDoc]">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <!-- Take first image (if any) -->
          <xsl:apply-templates select="outputPictures[1]" />
          <!-- Article heading and teaser text-->
          <h5><xsl:value-of select="articleHeading"/></h5>
          <!-- <p class="teaser"><xsl:value-of select="umbraco.library:TruncateString(artikel-Teasertekst,40,'...')"/></p> -->
        </a>
      </li>
    </xsl:template>
    
    <!-- Template for all excluded DocumentTypes -->
    <xsl:template match="Settings | SecretData | etc" priority="1">
            <!-- Suppress output... -->
    </xsl:template>

    (Note that you'll also need to flip the priority attribute to "1")

    /Chriztian 

  • Frederik T 241 posts 372 karma points
    Aug 29, 2011 @ 12:18
    Frederik T
    0

    I appreciate your reply, as my macro didnt originally work i let it be for the time being as i worked on other bits, now that you replied i returned to it, only to see that it doesnt work at all now.

    As in it doesnt display any items on the list at all, before or after your fix, so that isnt related i think. The macro is wired up, and it can display hardcoded text from the xslt (as a test to see if it worked at all). Really, really wierd...

    EDIT

    Ok i tried changing the test against maxItems to "greater than" instead of "less than" it it spat out EVERY document from that section. So there is a connection of sorts, but i still need to figure out whats wrong. Strange indeed...

  • Frederik T 241 posts 372 karma points
    Sep 01, 2011 @ 09:51
    Frederik T
    0

    Sorry for bumping, but i really hope someone can enlighten me on this.

Please Sign in or register to post replies

Write your reply to:

Draft