You just can't using your current setup, you'll always have to "hardcode" the Home link instead of the 'Site (NL)', unless you add a property so 'Site (NL)' (eg BreadcrumbURLName) will be used in your Razor file instead of .Name
I included the hard coded "home" link. My breadcrumb looks like this:
Home > Site (Nl) >Arrangementen
So now I only should find a way not to include the Site (NL) link in my breadcrumb. I guess I should do this by starting the for each loop one level down, but I don't know how to code this in Razor.
I still have a problem. I'm using a multilanguage website:
So when on an a Dutch page the breadcrumb should loop through all children of the node Site (NL) and when on a French page the breadcrumb should loop through all children of Site (Fr).
If you go to the introduction video tutorial of razor recipes, you can download the razor recipes package by clicking the 'download source code' link (at the bottom)
Thanks for the advice, I solved the problem in the meantime.
The problem that I had was showing the homenode in the correct language for each multilingual site. I have tackled this problem by using dictionary items:
problem with Razor breadcrumb
Hi,
For a Razor breadcrumb, I'm using this code from the Razor Recipes tutorial:
<ul id="breadcrumb" class="group">
@foreach (var level in @Model.Ancestors().Where("Visible"))
{
<li><a href="@level.Url">@level.Name</a> ></li>
}
<li>@Model.Name</li>
</ul>
The problem is that is starts building links one level too high.
This Razor code renders the following breadcrumb:
Site (NL) > Home
While it should only show: Home
Also, unlike the Razor Cookbook demo site my Text pages are not childnodes of the home node. So the breadcrumb rendered for the Text Pages is this
Site (NL) > Arrangementen
While it should be: Home > Arrangementen
My content tree in the Umbraco Backoffice looks like this:
Can someone help me with tweaking this Razor Breadcrumb code, so the breadcrumb is rendered correctly (that is to say, Home > Textpage)
Thanks for your help,
Anthony Candaele
Belgium
Anthony,
You just can't using your current setup, you'll always have to "hardcode" the Home link instead of the 'Site (NL)', unless you add a property so 'Site (NL)' (eg BreadcrumbURLName) will be used in your Razor file instead of .Name
Cheers,
/Dirk
Hi Dirk,
I included the hard coded "home" link. My breadcrumb looks like this:
Home > Site (Nl) >Arrangementen
So now I only should find a way not to include the Site (NL) link in my breadcrumb. I guess I should do this by starting the for each loop one level down, but I don't know how to code this in Razor.
Thanks for your help,
Anthony
http://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet is your friend.... Just use
where level is the level to start from..
Cheers,
/Dirk
Thanks a lot, this works. I just had to define a condition so that the breadcrumb doesn't render the home link twice when on the home page:
<ul id="breadcrumb" class="group">
@if (@Model.Name != "Home")
{
<li><a href="/">Home ></a></li>
}
@foreach (var level in @Model.Ancestors("Home").Where("Visible"))
{
<li><a href="@level.Url">@level.Name</a> ></li>
}
<li>@Model.Name</li>
</ul>
Greetings,
Anthony
I still have a problem. I'm using a multilanguage website:
So when on an a Dutch page the breadcrumb should loop through all children of the node Site (NL) and when on a French page the breadcrumb should loop through all children of Site (Fr).
Currently my breadcrumb script looks like this:
<ul id="breadcrumb" class="group">
@if (@Model.Name != "Home" && @Model.Name != "Accueil")
{
<li><a href="/">Home</a> ></li>
}
@foreach (var level in @Model.Ancestors().Where("Visible"))
{
<li><a href="@level.Url">@level.Name</a> ></li>
}
<li>@Model.Name</li>
</ul>
Is there a way to make the foreach loop start from the Site (NL) node when on a Dutch page, and start from Site (Fr) when on a French page?
Thanks for your help,
Anthony Candaele
Sorry to hijack, but where can we download the cookbook package?
If you go to the introduction video tutorial of razor recipes, you can download the razor recipes package by clicking the 'download source code' link (at the bottom)
greetings,
Anthony
Use AncestorOrSelf(1) to start from the first level instead of from the "Content" root node, maybe Ancestors(1) also work, haven't used that one yet.
Hi Sebastiaan,
Thanks for the advice, I solved the problem in the meantime.
The problem that I had was showing the homenode in the correct language for each multilingual site. I have tackled this problem by using dictionary items:
<ul id="breadcrumb" class="group">
@if (Model.NodeTypeAlias != "Homepage")
{
var output = umbraco.library.GetDictionaryItem("Homenode");
<li><a href="/">@output</a> ></li>
}
@foreach(var level in Model.Ancestors().Where("Visible"))
{
<li><a href="@level.Url">@level.Name</a> ></li>
}
<li>@Model.Name</li>
</ul>
greetings,
Anthony
Yup, that's what I usually do, well actually, I just hardcode the name really, how often are you going to change "Home" anyway.. :)
Did something a bite similar for my multilingual website and here is how my codes looks like
//fuji
is working on a reply...