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><a href="/">Home</a> ></li> } @if (@Model.Name =="Accueil") { <li><a href="/">Accueil</a> ></li> } // loop through the childnodes of 'Site (NL)' or 'Site (Fr)' @foreach (var level in @Model.Ancestors().Where("Visible")) { <li><a href="@level.Url">@level.Name</a> ></li> } <li>@Model.Name</li> </ul>
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
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:
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.
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.
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:
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><a href="/">Home</a> ></li>
}
@if (@Model.Name =="Accueil")
{
<li><a href="/">Accueil</a> ></li>
}
// loop through the childnodes of 'Site (NL)' or 'Site (Fr)'
@foreach (var level in @Model.Ancestors().Where("Visible"))
{
<li><a href="@level.Url">@level.Name</a> ></li>
}
<li>@Model.Name</li>
</ul>
Does anyone see the problem?
Thanks for you help,
Anthony Candaele
Belgium
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
And, why are you adding an '@' before Model in your if statement
Cheers,
/Dirk
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><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>
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><a 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
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
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
Yeah, sure, you can re-use any of the existing libraries..; so use
Cheers,
/Dirk
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><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
is working on a reply...