Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Oct 25, 2011 @ 11:07
    Anthony Candaele
    0

    Razor breadcrumb for multisite

    Hi,

    I have a multisite content structure:

    I created a Razor breadcrumb script, but the problem is that is shows the wrong home link when on the French website:

    Instead of Acceuil > Reservation for example, it renders as Home > Reservation

    My Razor script looks like this:

    <ul id="breadcrumb" class="group">
          // prevent 'home' link or 'acceuil' link from when
          // when on the 'home' page or 'acceuil' page
          @if (@Model.Name == "Home")
          
           <li><href="/">Home</a&gt;</li>
           }
          @if (@Model.Name =="Accueil")
          {
           <li><href="/">Accueil</a&gt;</li>
           }
         
         // loop through the childnodes of 'Site (NL)' or 'Site (Fr)'
         @foreach (var level in @Model.Ancestors().Where("Visible"))
           
           {       
            <li><href="@level.Url">@level.Name</a&gt;</li>       
           }
             
        <li>@Model.Name</li>
    </ul>

    Does anyone see the problem?

    Thanks for you help,

    Anthony Candaele

    Belgium

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 25, 2011 @ 13:06
    Dirk De Grave
    1

    Anthony,

    Don't know why, but would suggest to not use hard coded values for the name of the node, as soon as an editor changes it, your breadcrumb will blow up. I'd probably check the alias of the document type of those pages... Most probably using

    @if (Model.NodeTypeAlias == "DocTypeOfHomePage") {
    <li><a href="/">@Model.Name</a>&gt;</li>

    And, why are you adding an '@' before Model in your if statement

    @if (Model.Name == "Home") {
    // do whatever you need to do here
    }

     

    Cheers,

    /Dirk

     

     

     

     

     

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 25, 2011 @ 14:39
    Anthony Candaele
    0

    Hi Dirk,

    Sorry, as it are my first steps with Razor, sometimes I'm confused when, and when not to use the '@' sign. Now I know that in the statement of a condition one should not use the '@' sign.

    Concerning the breadcrumb for my multisite, this code works:

    <ul id="breadcrumb" class="group">
          
         @if (Model.NodeTypeAlias != "Homepage")
              {
               <li><href="/">Home</a></li>
               }
              
         @foreach (var level in @Model.Ancestors().Where("Visible"))
             
             {
              
                <li><href="@level.Url">@level.Name</a&gt;</li>       
             }
            
         
        <li>@Model.Name</li>
    </ul>

    But the problem remains that for the pages under the Site (Fr) node the breadcrumb is still:

    Home > Reservation etc ... while it should be Accueil > Reservation

    So I guess to solve this problem I should find a way to output the .Name property of the node with

    the NodeTypeAlias of "Homepage".

    Something like:

    @if (Model.NodeTypeAlias != "Homepage")
              {
               <li><href="/">name of the node with NodeTypeAlias == "Homepage"</a></li>
               }

    Phew, I didn't know breadcrumbs could be that tricky

    Thanks for your help,

    Anthony

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 25, 2011 @ 14:51
    Dirk De Grave
    0

    Anthony,

    Concerning the @ sign, you statement doesn't make sense... you need to have the '@' as soon as you start swithing between html and Razor context... So, as soon as you enter a piece of html, and then wishes to write some c# code, you'd need the '@' sign. As long as you stay in c# - or code context - there's no need to add to '@' sign for any of the vars or reserved words.

     

    Cheers,

    /Dirk

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 26, 2011 @ 10:02
    Anthony Candaele
    0

    Hi Dirk,

    Oh I see, thanks for the advice. Concerning the problem with the home node in my breadcrumb, I'll think I will need to solve this with dictionary items, so that the home link shows 'Accueil' when on a French content page and 'Home' when on a Dutch content page. I wonder if it is possible to use dictionary items in a Razor script.

    greetings,

    Anthony

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 26, 2011 @ 10:13
    Dirk De Grave
    1

    Yeah, sure, you can re-use any of the existing libraries..; so use

    var output = umbraco.library.GetDictionaryItem("dictItemName");

     

    Cheers,

    /Dirk

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 26, 2011 @ 11:03
    Anthony Candaele
    0

    Hi Dirk,

    Thanks a lot for your help. My breadcrumb works exactly as needed now. On a French content page the label for the rendered homelink is 'Accueil' and on a Dutch page the label for the rendered homelink is 'Home'. My script looks like this:

    <ul id="breadcrumb" class="group">
      @if (Model.NodeTypeAlias != "Homepage")
      {
       var output umbraco.library.GetDictionaryItem("Homenode");
       <li><href="/">@output</a></li>
       }
      @foreach(var level in Model.Ancestors().Where("Visible"))
      {
         <li><href="@level.Url">@level.Name</a></li>
      }
      <li>@Model.Name</li>
    </ul>

     

    Greetings,

    Anthony

Please Sign in or register to post replies

Write your reply to:

Draft