November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
You are not alone who finds this too over engineering :)
Anyway this is more related to C# and Mvc idioms and so much about EPiServer. In this particular case Func<TArg,TResult> is a function this may be passed in as argument to MenuList method. This function represents "some code block" that may be called later while generating menu.
In AlloyTech Func<> is actually generated by view engine - in this case Razor. In this case you are declare this helper method inline while calling to MenuList method. Is it more clear if you look at following code?
@helper RenderItem(HtmlHelpers.MenuItem item)
{
<li class="@(item.Selected ? "active" : null)">
@Html.PageLink(item.Page, null, new { @class = string.Join(" ", item.Page.GetThemeCssClassNames()) })
</li>
}
and then:
@Html.MenuList(ContentReference.StartPage, RenderItem)
Thank you Valdis!
You made it some what more clear but i still feel quite confused. :)
I'm not the person to say if this code is over engineerd or not but i think it's hard to understand and i need to practise more!
I found this link if there is any one else out there also confused: http://vibrantcode.com/blog/2010/8/2/inside-razor-part-3-templates.html
Please feel free to post links that explains this way of programming :)
Regards
David
Could some one please help me and explain how the MenuList in Alloy MVC templates works. As a junior developer i find it very complex.
The most confusing part is the Func<MenuItem, HelperResult> itemTemplate = null part. I cant get my head around what this parameter is when the method is called. Please help.
@Html.MenuList(ContentReference.StartPage,
@<li class="@(item.Selected ? "active" : null)">
@Html.PageLink(item.Page, null, new { @class = string.Join(" ", item.Page.GetThemeCssClassNames())})
</li>)
public static IHtmlString MenuList(
this HtmlHelper helper,
ContentReference rootLink,
Func<MenuItem, HelperResult> itemTemplate = null,
bool includeRoot = false,
bool requireVisibleInMenu = true,
bool requirePageTemplate = true)
{}