Copied to clipboard

Flag this post as spam?

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


  • Eric Anatas 10 posts 30 karma points
    Nov 29, 2010 @ 23:13
    Eric Anatas
    0

    Do Umbraco XLST templates always have to be based off $currentPage?

    I'm trying to setup a top navigation bar on my Umbraco site using version 4.5.2. My site structure looks something like this


    Content
         Home
         Resume
         Portfolio
               School
               Job 1
               Job 2
         Activities
         Projects
              Project 1
              Project 2
         Contact

    Now I want a Top navigation bar that lists the following regardless of what page or page level the user is at.


    Home| Resume | Portfolio | Activities | Projects | Contact


    Most of the examples I've seen for navigation bars use a for-each statement like the one shown below.

    <xsl:template match="/">

    <ul>
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>

    </xsl:template>


    I want to show *all* the level 1 documents (Home, Resume, Portfolio etc..). Yet if I set @level = 1 the XLST above shows the children of the level 1 ancestor of the current page. Which makes sense because that's what this XLST above should do:

    <!-- Front the current page find the ancestor (or self) that has a level = 1
    $currentPage/ancestor-or-self::* [@level=$level]

    <!--Find all children of the level 1 ancestor that are a doc and not hidden-->
    /* [@isDoc and string(umbracoNaviHide) != '1']

    So what I found is that I can then find the parent of the level 1 ancestor of the current page, and then find all the children of that parent and then get all the level 1 documents.

    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/parent::*/* [@isDoc and string(umbracoNaviHide) != '1']">


    This, however, seems like an incredibly round about way of accessing all the level 1 documents. Can I instead write a XPath query based of the root of the entire site rather then the $currentPage?

    Also, is there someway to download the XML for an entire site or at least a the current page so I can have a better understanding of what the XLST I'm writing is working on?

  • Kim Andersen 1447 posts 2197 karma points MVP
    Nov 30, 2010 @ 00:13
    Kim Andersen
    0

    Hi Eric

    If you want to create a top navigation with only nodes on level 1 you can change your for-each statement to this:

    <xsl:for-each select="$currentPage/ancestor-or-self::root/* [string(umbracoNaviHide) != '1' and @isDoc]">

    /Kim A

  • Kim Andersen 1447 posts 2197 karma points MVP
    Nov 30, 2010 @ 00:18
    Kim Andersen
    0

    Ohh, and if you want to check out the XML for the whole site you can find it in the /App_Data/umbraco.config-file. This file contains all of the published XML.

    Another way is to use an extension called GetXmlAll like this:

    <textarea>
        <xsl:copy-of select="umbraco.library:GetXmlAll()" />
    </textarea>

    This will also give you the entire XML from the page. I hope this can help you a bit :)

    /Kim A

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 30, 2010 @ 02:16
    Chriztian Steinmeier
    0

    Hi Eric (+Kim)

    When I started with Umbraco I had the same thoughts about the way your XSLT gets its XML (if you're used to XSLT it's weird that all you get is a <macro> element...), but now I actually think that the currentPage parameter is a tiny piece of genius (whether it's intended or not). In every other XSLT-based CMS I've dealt with, I only had access to a subset of the XML and particularly in navigations, I had to manually find the current page based on a top-level "selectedPage" (or similarly named) attribute.

    In Umbraco, I always have access to the full site just by using the currentPage parameter - and if I'm only interested in that page and its children (many macros share that idea) it's the easiest thing to write an XPath for.

    What I normally do is to add a variable just after the currentPage parameter, like this:

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

    (I actually use "Website" instead of "*[@level = 1]" but that's because I always use a Document Type called "Website" for the root of my sites. Using level will make it work not only in many installations, but also in either of the two XML formats currently being used.)  

    This will enable me to select nodes either based off of the current page, or from the root of the website. I hardly ever need to go all the way to the Content root, but if I do, it's a matter of doing $siteRoot/ancestor::root or $currentPage/ancestor-or-self::root to get there. (We have to use ancestor-or-self:: when using currentPage, to safeguard against the moment where the XSLT file is saved, because Umbraco will run a transform using Content (<root>) as currentPage, which will then fail to select an ancestor called "root". Phew -lengthy explanation :-)

    @Kim: Calling GetXmlAll() makes no sense to me because you already have everything in memory - just use <xsl:copy-of select="$currentPage/ancestor-or-self::root" /> to get it. I don't know for sure, but I'm guessing that using GetXmlAll() will fetch an entire new copy of everything... could be a lot, right? (I've even seen some reports, that GetXmlAll() includes RecycleBin items (w000t??) - don't want those...

    /Chriztian 

  • Eric Anatas 10 posts 30 karma points
    Nov 30, 2010 @ 02:59
    Eric Anatas
    0

    Thanks guys, these responses have been extreemly helpful. I like the idea of creating a "siteRoot" variable. However, now I'm a little confused as to what Umbraco considers the "Root" of a site. In the admin interface it looks as though the root of the site is the content node, but this is not an actual document. The content node can then contain multiple subnodes.

    Like I mentioned above my current site has the following structure

    Content
         Resume
         Portfolio
            Education
            Job 1
            Job 2
         Project
              Project 1
              Project 2
         Contact

    Should I instead move all my root pages under a single root page?

    Content
         MySiteRoot
              Resume
              Portfolio
                 Education
                Job 1
                Job 2
              Project
                   Project 1
                   Project 2
              Contact

  • Rich Green 2246 posts 4008 karma points
    Nov 30, 2010 @ 08:40
    Rich Green
    1

    Hi Eric,

    It's pretty much standard practice to include a "Home" or root "Website" node, the xslt templates examples are set up for this structure, so your 2nd structure will work much better.

    Content
         MySiteRoot (or HOME)
              Resume
              Portfolio
                 Education
                Job 1
                Job 2
              Project
                   Project 1
                   Project 2
              Contact

    With regards to where the "root" node is, this kind of depends what you mean by root, as you can run multiple sites within umbraco, you could have this structure:

    Content
         Website 1 (or HOME 1)
              Resume
              Portfolio
                 Education
                Job 1
                Job 2
              Project
                   Project 1
                   Project 2
              Contact

         Website 2 (or HOME 2)
              Resume
              Portfolio
              Project
                   Project 1
                   Project 2
              Contact

    I'm not sure there is a agreed definition of what "root" is, but generally I would say that "current root" is the root of the website you are in (either Website 1 or Website 2 above) or the "absolute root" which is the "Content" node.

    Rich

  • Kim Andersen 1447 posts 2197 karma points MVP
    Nov 30, 2010 @ 14:03
    Kim Andersen
    0

    @Chriztian:

    Yeah you might have a point about GetXmlAll making another copy of what we have already got in memory. But I think it's a fine option when learning the XML schema of Umbraco like Eric sound like he wants :)

    I can't remember that I have ever used the extension besides when I needed to see the entire XML in debugging/star up/learning the schema etc. Just tried to make the call on a test solution and I didn't get the items in the recycle bin - I had to try it out :D

    /Kim A

  • Eric Anatas 10 posts 30 karma points
    Nov 30, 2010 @ 21:35
    Eric Anatas
    0

    Yeah exactly I just want to verify that when things don't work it's because my XSLT is wrong and not my understanding of the XML it is translating.


    I modified my site to have a root "Home" page which contains all my other pages as suggested. Now say I wanted to setup a second website on this single Umbraco install. How do I control what page a user is sent to when they browse to my root domain name. For example this is for my personal website: www.ericanastas.com. Now when I browse to that URl the root Home page is opened.

    Now what if I wanted to create another domain or sub domain that opened another website/root page in Umbraco. Say I wanted to have photos.ericanastas.com open up a separate site of my photography?

  • Rich Green 2246 posts 4008 karma points
    Nov 30, 2010 @ 21:59
    Rich Green
    0

    Hey Eric,

    Right click the 'Home' node of your new website and select 'Manage Hostnames', this is how you specify which site you want to load.

    Unless there is a good reason not to (hosting costs, or the sites are closely related) I would recommend setting up a new Umbraco install for each new site.

    Rich

Please Sign in or register to post replies

Write your reply to:

Draft