Does your website look a bit like this?
My drawing skills leaves something to be desired, so lets point out the elements of a typical web page:
These are standard elements you will find in many EPiServer projects, and they have been used in one form or another in all the projects I have worked on. I have seen plenty of implementations of these elements, enough to never want to write another one. One of the major goals of the EPiUtilities project was to create web controls for these elements which only needs to be told what to look like, and then the control does the rest of the heavy lifting.
At release, the EPiUtilities project contains the following controls:
- BreadCrumbsMenu
- LinkItemList
- MultiLevelMenu
- OneLevelMenu
- PageDataList
- PagedPageDataList
You specify what the output of the control should look like with templates, and configure it’s behavior with parameters. In most cases you will not have to write a single line of code to create working elements like those in the figure above.
A simple example which lists the child pages of a page would look like this:
<EPiUtil:PageDataList runat="server" AutoBind="true" Pages="<%# CurrentPage.ChildrenForVisitor() %>">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<%# Container.Item.ToHtmlAnchorWithLinkUrlAndPageName() %></li>
</ItemTemplate>
<FooterTemplate>
</ul></FooterTemplate>
</EPiUtil:PageDataList>
It may seem simple, and isn’t there a PageDataList in EPiServer already? Well, yes, but this control has more functionality and it comes with some friends which do not. The PageDataList also has a subclass with paging functionality, and a full example could look like this:
<EPiUtil:PagedPageDataList runat="server" AutoBind="true" SortOrder="Alphabetical"
PageSize="10" PagingQueryParameterKey="p" Pages="<%# CurrentPage.ChildrenForVisitor() %>">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<FirstItemTemplate>
<li class="first">
<%# Container.Item.ToHtmlAnchorWithLinkUrlAndPageName() %></li>
</FirstItemTemplate>
<SecondItemTemplate>
<li class="second">
<%# Container.Item.ToHtmlAnchorWithLinkUrlAndPageName() %></li>
</SecondItemTemplate>
<ThirdItemTemplate>
<li class="third">
<%# Container.Item.ToHtmlAnchorWithLinkUrlAndPageName() %></li>
</ThirdItemTemplate>
<FourthItemTemplate>
<li class="fourth">
<%# Container.Item.ToHtmlAnchorWithLinkUrlAndPageName() %></li>
</FourthItemTemplate>
<ItemTemplate>
<li>
<%# Container.Item.ToHtmlAnchorWithLinkUrlAndPageName() %></li>
</ItemTemplate>
<AlternatingItemTemplate>
<li class="alt">
<%# Container.Item.ToHtmlAnchorWithLinkUrlAndPageName() %></li>
</AlternatingItemTemplate>
<SeparatorTemplate>
<li>Separator</li></SeparatorTemplate>
<FooterTemplate>
</ul></FooterTemplate>
<PagerHeaderTemplate>
<ul>
</PagerHeaderTemplate>
<PagerItemTemplate>
<li><a href="<%# Container.Url %>">
<%# Container.Text %></a></li></PagerItemTemplate>
<PagerSelectedItemTemplate>
<li>
<%# Container.Text %></li></PagerSelectedItemTemplate>
<PagerFooterTemplate>
</ul></PagerFooterTemplate>
<EmptyTemplate>
<p>
This list has no items.</p>
</EmptyTemplate>
</EPiUtil:PagedPageDataList>
To use these controls in your project you can simply get the EPiUtilities package from EPiServer nuget. If you prefer to build the code yourself, the source can be found at Github.
To use the controls without any declarations in your aspx/ascx, you need to declare the controls and namespace in web.config instead. The nuget package will try to transform the web.config for you, but if you have some fancy config generation setup or if you build the code yourself the necessary bits look like this:
<configuration>
<system.web>
<pages>
<controls>
<add tagPrefix="EPiUtil" namespace="EPiUtilities.WebControls" assembly="EPiUtilities" />
</controls>
<namespaces>
<add namespace="EPiUtilities.Extensions" />
</namespaces>
</pages>
</system.web>
</configuration>
In future blog posts I will go into each of the controls in detail.