I am working on converting my super sweet XSLT files to razor. I kinda need at few tips/tricks or links now.
I would like to add protection to my menu. In my xslt it's done like this:
and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())
The other thing I need to figure out is how to hide certian doctypes. In XSLT I do it like this:
and name() != 'Produkt'
My new razor menu looks like this:
@inherits umbraco.MacroEngines.DynamicNodeContext@{varstartNodeID=Parameter.source;varhomeName=Parameter.frontPage;varhomeLink=@Model.NodeById(startNodeID);varhomeCurrent="current";}@* Fjerner current class hvis ikke på forsiden (kigger på doctype alias) *@@if(Model.NodeTypeAlias!="Forside"){homeCurrent="";}@if(startNodeID!=null){varstartNode=Library.NodeById(startNodeID);if(startNode.Children.Where("Visible").Any()){<ulclass="topmenu"><liclass="@homeCurrent"><ahref="@homeLink.Url">@homeName</a></li>@* Loop undersider *@@foreach(varpageinstartNode.Children.Where("Visible")){<liclass="@page.IsAncestorOrSelf(Model,"current","")"><ahref="@page.Url">@page.Name</a><ul>@* LVL 2 *@@foreach(varsubpageinpage.Children.Where("Visible")){<li><ahref="@subpage.Url">@subpage.Name</a><ul>@* LVL 3 *@@foreach(varsubsubpageinsubpage.Children.Where("Visible")){<li><ahref="@subsubpage.Url">@subsubpage.Name</a></li>}</ul></li>}</ul></li>}</ul>}}
Thank you for the quick respond and the solution :)
Upgraded my Razor so it now can hide both protected pages and the doctypes i need. My code now looks like this:
@inherits umbraco.MacroEngines.DynamicNodeContext@{varstartNodeID=Parameter.source;varhomeName=Parameter.frontPage;varhomeLink=@Model.NodeById(startNodeID);varhomeCurrent="current";}@* Fjerner current class hvis ikke på forsiden (kigger på doctype alias) *@@if(Model.NodeTypeAlias!="Forside"){homeCurrent="";}@if(startNodeID!=null){varstartNode=Library.NodeById(startNodeID);if(startNode.Children.Where("Visible").Any()){<ulclass="topmenu"><liclass="@homeCurrent"><ahref="@homeLink.Url">@homeName</a></li>@* Loop undersider *@@foreach(varpageinstartNode.Children.Where("Visible")){if(page.HasAccess){<liclass="@page.IsAncestorOrSelf(Model,"current","")"><ahref="@page.Url">@page.Name</a><ul>@* LVL 2 *@@foreach(varsubpageinpage.Children.Where("Visible")){if(subpage.HasAccess){<li><ahref="@subpage.Url">@subpage.Name</a><ul>@* LVL 3 *@@foreach(varsubsubpageinsubpage.Children.Where("Visible")){if(subsubpage.HasAccess&&subsubpage.NodeTypeAlias!="doctypeAliasHere"){<li><ahref="@subsubpage.Url">@subsubpage.Name</a></li>}}</ul></li>}}</ul></li>}}</ul>}}
There might be a smarter way to build it, but it works now, thanks again Dennis :)
Razor menu with protection and hidden doctypes
Hi guys
I am working on converting my super sweet XSLT files to razor. I kinda need at few tips/tricks or links now.
I would like to add protection to my menu. In my xslt it's done like this:
The other thing I need to figure out is how to hide certian doctypes. In XSLT I do it like this:
My new razor menu looks like this:
Any help/pointers would be much appreciated. :)
/Michael
Hi Michael,
For the IsProtected or HasAccess http://umbraco.com/follow-us/blog-archive/2011/3/13/umbraco-razor-feature-walkthrough-part-5.aspx
The way that you can get nodes with at specific document type is:
@foreach (var item in Model.NewsItems.Where("Visible"))
Or you could do:
Hope that helps,
/Dennis
Hi Dennis
Thank you for the quick respond and the solution :)
Upgraded my Razor so it now can hide both protected pages and the doctypes i need. My code now looks like this:
There might be a smarter way to build it, but it works now, thanks again Dennis :)
/Michael
is working on a reply...