Copied to clipboard

Flag this post as spam?

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


  • bob singh 47 posts 126 karma points
    Nov 07, 2013 @ 16:51
    bob singh
    0

    masterpage top navigation and uBlogsy webform website

    Hi All.

    I am a newbie at xslt.

    I have an Umbraco v6.0.3 website that has a masterpage (umbMaster) and a dynamic top menu that is being generated by a Macro that calls some xslt  -

    I have now installed uBlogsy_Webforms_3.0_Beta and this has installed a blog as a sibling website within the existing website.

    So to get the blog to inherit the same look and feel I then pointed the top uBlogsy masterpage (_uBlogsyBaseSite) to the umbMaster masterpage and this works fine.

    My problem is that when I navigate to the blog, the dynamic menu does not show the menu items as the rest of the website, I am assuming this is because it is a sibling website but I want it to show the same menu items as the rest of the website.

    Below is a copy of the xslt that is called by the macro umbTopNavigation, if someone could show me what to modify in the xslt to get the absolute root when I am on the blog

    I will the detect if the user is on the blog, by the url, and define a different xslt call from the umbTopNavigation macro when the blog is used -

    Thank you!

               <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
        <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library"
      exclude-result-prefixes="msxml umbraco.library">


        <xsl:output method="xml" omit-xml-declaration="yes" />

        <xsl:param name="currentPage"/>

        <!-- Input the documenttype you want here -->
        <xsl:variable name="level" select="1"/>

        <xsl:template match="/">

     <div id="menu">    
     <ul class="topNavigation">
         <li class="home">
             <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
                 <xsl:attribute name="class">home current</xsl:attribute>
             </xsl:if>
             <a href="/">Home</a>
           </li>

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

      <li>
         
        <xsl:if test="$currentPage/@id = current()/@id">
                <xsl:attribute name="class">current</xsl:attribute>
            </xsl:if>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        <xsl:if test="count(./child::*[@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
          <ul class="levelTwo">
            <xsl:for-each select="./child::*[@isDoc and string(umbracoNaviHide) != '1']">
              <li>
                <xsl:if test="$currentPage/@id = current()/@id">
                <xsl:attribute name="class">current</xsl:attribute>
            </xsl:if>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
                  <xsl:if test="count(./child::*[@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
                      <ul class="levelThree">
                        <xsl:for-each select="./child::*[@isDoc and string(umbracoNaviHide) != '1']">
                          <li>
                            <a href="{umbraco.library:NiceUrl(@id)}">
                              <xsl:value-of select="@nodeName"/>
                            </a>
                          </li>
                        </xsl:for-each>
                      </ul>  
                    </xsl:if>
              </li>
            </xsl:for-each>
          </ul> 
        </xsl:if>
      </li>


    </xsl:for-each>
    </ul>
            </div>
        </xsl:template>

    </xsl:stylesheet>        





       

     

  • bob singh 47 posts 126 karma points
    Nov 07, 2013 @ 17:14
    bob singh
    0

     My website structure is like the following simple example

    • Main website
      -- Main Menu Item 2.1
      -- Main Menu Item 2.2
    • uBlogsy website
      -- uBlogsy Menu Item 2.1

    Therefore when the user is navigating to http://x.com the top menu bar will display | Home | Main menu Item 2.1 | Main menu Item 2.2 |

    BUT when the user is on http://x.com/Blog the top menu displays | Home | uBlogsy Menu Item 2.1 |

    and I want it to display | Home | Main menu Item 2.1 | Main menu Item 2.2 |

    One way would be to move the uBlogsy website into the Main website but I am too late in the project to attempt this

    BTW Any help is appreciated here.

  • bob singh 47 posts 126 karma points
    Nov 07, 2013 @ 18:29
    bob singh
    0

    Please see image below

  • bob singh 47 posts 126 karma points
    Nov 07, 2013 @ 18:32
    bob singh
    0

  • bob singh 47 posts 126 karma points
    Nov 07, 2013 @ 18:48
    bob singh
    0

    I guess I could dump the menu html at runtime that is generated by the following

          <div id="mainmenu">
                <umbraco:Macro Alias="umbTopNavigation" runat="server"></umbraco:Macro>
        </div>

    into a variable called blogmenu

    var blogmenu = $('#mainmenu').html();

    and output blogmenu instead when the blog shows but I though there would be a better way to do it through the xslt?

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 07, 2013 @ 20:07
    Chriztian Steinmeier
    1

    Hi Bob,

    It's pretty simple actually - you just need to adjust the XSLT to grab a few variables, to keep check of where you are. Here's a version that should render the Site menu, regardless of the section you're in (you need to fill in the two aliases in ALL_CAPS):

    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="msxml umbraco.library">
    
        <xsl:output method="xml" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage"/>
    
        <!-- Grab a reference to the <root> element that is parent of both the site and the blog -->
        <xsl:variable name="absoluteRoot" select="$currentPage/ancestor::root" />
    
        <!-- Grab the Site Home -->
        <xsl:variable name="siteRoot" select="$absoluteRoot/SITE_HOME_ALIAS" />
    
        <!-- Grab the uBlogsy root -->
        <xsl:variable name="blogRoot" select="$absoluteRoot/BLOG_ROOT_ALIAS" />
    
        <!-- Input the documenttype you want here -->
        <xsl:variable name="level" select="1"/>
    
        <xsl:template match="/">
            <div id="menu">
                <ul class="topNavigation">
                    <li class="home">
                        <xsl:if test="$currentPage/@id = $siteRoot/@id">
                            <xsl:attribute name="class">home current</xsl:attribute>
                        </xsl:if>
                        <a href="/">Home</a>
                    </li>
                    <xsl:for-each select="$siteRoot/*[@isDoc and not(umbracoNaviHide = 1)]">
                        <li>
                            <xsl:if test="@id = $currentPage/@id">
                                <xsl:attribute name="class">current</xsl:attribute>
                            </xsl:if>
                            <a href="{umbraco.library:NiceUrl(@id)}">
                                <xsl:value-of select="@nodeName"/>
                            </a>
                            <xsl:if test="*[@isDoc and not(umbracoNaviHide = 1)]">
                                <ul class="levelTwo">
                                    <xsl:for-each select="*[@isDoc and not(umbracoNaviHide = 1)]">
                                        <li>
                                            <xsl:if test="@id = $currentPage/@id">
                                                <xsl:attribute name="class">current</xsl:attribute>
                                            </xsl:if>
                                            <a href="{umbraco.library:NiceUrl(@id)}">
                                                <xsl:value-of select="@nodeName"/>
                                            </a>
                                            <xsl:if test="*[@isDoc and not(umbracoNaviHide = 1)]">
                                                <ul class="levelThree">
                                                    <xsl:for-each select="*[@isDoc and not(umbracoNaviHide = 1)]">
                                                        <li>
                                                            <a href="{umbraco.library:NiceUrl(@id)}">
                                                                <xsl:value-of select="@nodeName"/>
                                                            </a>
                                                        </li>
                                                    </xsl:for-each>
                                                </ul>  
                                            </xsl:if>
                                        </li>
                                    </xsl:for-each>
                                </ul>  
                            </xsl:if>
                        </li>
                    </xsl:for-each>
                </ul>
            </div>
        </xsl:template>
    </xsl:stylesheet>
    

    (I cleaned it up a bit - you could also get rid of the repetition with the links etc. but that's not the focus here :-)

    Hope you can see how it works, otherwise let me know!

    /Chriztian

  • bob singh 47 posts 126 karma points
    Nov 08, 2013 @ 11:13
    bob singh
    0

    Chriztian, excellent, many thanks!

    Bob

Please Sign in or register to post replies

Write your reply to:

Draft