Copied to clipboard

Flag this post as spam?

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


  • dominik 711 posts 733 karma points
    Sep 10, 2012 @ 17:05
    dominik
    0

    XSLT to razor problem

    Hello,

    We are trying to switch our navigation from XSLT to razor.

    Here is some of our XSLT script we are currently using:

    <!-- Show Top List item -->
          <xsl:for-each select="$currentPage/ancestor-or-self::* [@level = 1]/* [string(umbracoNaviHide) != '1' and @isDoc]">
            <xsl:if test="count(./*[@isDoc])&gt; 0 and count($currentPage/ancestor-or-self::*[@id = current()/@id]) &gt; 0 ">
              <div>
                <xsl:attribute name="class">
                  top-item
                    <xsl:value-of select="$currentPage/menuClass"/>
                 </xsl:attribute>
                <href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:if test="@id = $currentPage/@id">
                    <xsl:attribute name="class">
                      <xsl:value-of select="menuClass"/>
                    </xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="umbraco.library:Replace(@nodeName, '|', '&lt;br/&gt;')" disable-output-escaping="yes"/>
                </a>
              </div>
            </xsl:if>
          </xsl:for-each>

    I tried a few navigation examples but i am not able to achieve the same as my XSLT does.

    Perhaps someone can just tell me where to start :-)

    Thanks a lot

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Sep 10, 2012 @ 19:10
    Jan Skovgaard
    0

    Hi Dominik

    What does your Razor code currently look like? And what part of the above XSLT is it that you're having trouble figuring out how you should do in Razor?

    /Jan

  • dominik 711 posts 733 karma points
    Sep 10, 2012 @ 19:45
    dominik
    0

    HI Jan,

    I dont exactly know how to start.

    What i have tried so far:

     var topLevelItems Model.AncestorOrSelf(1);
                                       
                    foreach(dynamic item in topLevelItems{
                      <div class="top-item @item.menuClass">
                        <a href="@item.id" class="@item.menuClass">@item.NodeName</a>
                      </div>
     
    But I think i am completly wrong or?
     

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 10, 2012 @ 20:37
    Fuji Kusaka
    0

    Hi Dominik,

    You could try doing it this way

    @{  
      var topLevelItems = Model.AncestorOrSelf(1);
      const string selectedClass = " class=\"menuClass\"";
      }

     <ul>
            
            <div@Library.If(topLevelItems.DescendantOrSelf(Model), selectedClass)><a href="@topLevelItems .Url">@topLevelItems.Name</a></div>

            @foreach(var page in topLevelItems.Children.Where("Visible"))
            {
                <div@Library.If(page.IsAncestorOrSelf(Model), selectedClass)>               
                        <a href="@page.Url">@page.Name</a>                    
                    @if (page.Children.Count() > 0)
                    {                   
                           foreach (var childPage in page.Children)
                            {
                                <a href="@childPage.Url">@childPage.Name</a></li>
                            }                  
                    }            
                </div>
            }
    </ul>

     

    Hope this will help

  • dominik 711 posts 733 karma points
    Sep 11, 2012 @ 10:28
    dominik
    0

    HI Fuji,

    I tried your code but it shows The name 'Library' does not exist in the current context

    I am using umbraco 4.7.0 and for now i am not able to update to a newer version

     

  • dominik 711 posts 733 karma points
    Sep 11, 2012 @ 10:57
    dominik
    0

    Hello together,

    Now i was able to build my navigation but a few things are still missing.

    It should just the sub items of the active page and not all.

    In xslt i achieved this by using:

    $currentPage/ancestor-or-self::*

    Also in XSLT i got the document type property for my css class by using:

    <xsl:value-of select="menuClass"/>

    How can i get this in razor?

    Here is the razor script i created already:

    @{  
      var topLevelItems Model.AncestorOrSelf(2);
    }
       
    <div class="top-item oligo"><href="@topLevelItems.Url">@topLevelItems.Name</a></div>
    @foreach (var page in Model.AncestorOrSelf(2).Children.Where("Visible"))
    {
       <ul>
         <li><href="@page.Url">@page.Name</a>
           @if (page.Children.Where("Visible").Count(0)
             {
              <ul>
               @foreach (var subpage in page.Children.Where("Visible"))
                 {
                  <li><href="@subpage.Url">@subpage.Name</a>
                  
                  @if (subpage.Children.Where("Visible").Count(0)
                   {
                    <ul>
                     @foreach (var subsubpage in subpage.Children.Where("Visible"))
                       {
                        <li><href="@subsubpage.Url">@subsubpage.Name</a></li>
                       }
                  </ul>
                   }
                </li>
                 }
            </ul>
             }
         </li>
     </ul>
    }

    Thanks

  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 11, 2012 @ 11:25
    Fuji Kusaka
    0

    Hi Dominik, 

    Can you add the namespace 

    using umbraco.MacroEngines.Library;

    And secondly try to add this 

    <[email protected](page.IsAncestorOrSelf(Model), selectedClass)> // to the parent top <li>
  • dominik 711 posts 733 karma points
    Sep 11, 2012 @ 11:36
    dominik
    0

    Hi Fuji,

    Again it shows  The type or namespace name 'Library' does not exist in the namespace 'umbraco.MacroEngines' (are you missing an assembly reference?)

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 11, 2012 @ 11:55
    Fuji Kusaka
    0

    ok looks like @library wont help, try this instead

    <li class="@(page.Id == Model.Id ? "selectedClass" : "")"></li>
  • dominik 711 posts 733 karma points
    Sep 11, 2012 @ 12:01
    dominik
    0

    The correct css class i got working by creating a helper method. But still I need a solution to just open the parent ul and not all ul so only the subnodes of the parent list are shown.

     

  • dominik 711 posts 733 karma points
    Sep 11, 2012 @ 12:20
    dominik
    0

    This is how i have done it in XSLT:

    <!-- Open only current page with sub structure-->
    <xsl:if test="count(./*[@isDoc])&gt; 0 and count($currentPage/ancestor-or-self::*[@id = current()/@id]) &gt; 0 ">
       <xsl:if test="$currentPage/ancestor-or-self::*  [@level > 2]/*  [@isDoc and string(umbracoNaviHide) != '1']"> 

  • dominik 711 posts 733 karma points
    Sep 12, 2012 @ 15:29
    dominik
    0

    Any idea how to achieve the followin in razor?

    My navigation looks like

    List1
    - List1.1
    - List1.2
    List2
    - List2.1
    - List2.2
    List3 
    - List3.1
    - List3.2

    What i want to achieve is that if i stay on List1.2 for example it should just open the first <ul> so it looks like:

     List1
    - List1.1
    - List1.2
    List2
    List3 

     

    Thanks

  • dominik 711 posts 733 karma points
    Sep 17, 2012 @ 12:44
    dominik
    0

    Is there any integrated method in razor to only expand the parent list as described above?

    I am still searching for a solution

  • dominik 711 posts 733 karma points
    Oct 04, 2012 @ 12:31
    dominik
    0

    I am still searching for an solution - it would be great if someone can help

  • dominik 711 posts 733 karma points
    Oct 26, 2012 @ 11:28
    dominik
    0

    i am still searching for an idea how to achieve the following in razor script:

      <xsl:if test="count(./*[@isDoc])&gt; 0 and count($currentPage/ancestor-or-self::*[@id = current()/@id]) &gt; 0 ">

Please Sign in or register to post replies

Write your reply to:

Draft