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?
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?
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.
<!-- Open only current page with sub structure--> <xsl:if test="count(./*[@isDoc])> 0 and count($currentPage/ancestor-or-self::*[@id = current()/@id]) > 0 "> <xsl:if test="$currentPage/ancestor-or-self::* [@level > 2]/* [@isDoc and string(umbracoNaviHide) != '1']">
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:
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
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
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?
Hi Dominik,
You could try doing it this way
Hope this will help
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
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"><a href="@topLevelItems.Url">@topLevelItems.Name</a></div>
@foreach (var page in Model.AncestorOrSelf(2).Children.Where("Visible"))
{
<ul>
<li><a href="@page.Url">@page.Name</a>
@if (page.Children.Where("Visible").Count() > 0)
{
<ul>
@foreach (var subpage in page.Children.Where("Visible"))
{
<li><a href="@subpage.Url">@subpage.Name</a>
@if (subpage.Children.Where("Visible").Count() > 0)
{
<ul>
@foreach (var subsubpage in subpage.Children.Where("Visible"))
{
<li><a href="@subsubpage.Url">@subsubpage.Name</a></li>
}
</ul>
}
</li>
}
</ul>
}
</li>
</ul>
}
Thanks
Hi Dominik,
Can you add the namespace
And secondly try to add this
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?)
ok looks like @library wont help, try this instead
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.
This is how i have done it in XSLT:
<!-- Open only current page with sub structure-->
<xsl:if test="count(./*[@isDoc])> 0 and count($currentPage/ancestor-or-self::*[@id = current()/@id]) > 0 ">
<xsl:if test="$currentPage/ancestor-or-self::* [@level > 2]/* [@isDoc and string(umbracoNaviHide) != '1']">
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
Is there any integrated method in razor to only expand the parent list as described above?
I am still searching for a solution
I am still searching for an solution - it would be great if someone can help
i am still searching for an idea how to achieve the following in razor script:
<xsl:if test="count(./*[@isDoc])> 0 and count($currentPage/ancestor-or-self::*[@id = current()/@id]) > 0 ">
is working on a reply...