How many times have any of you created a function that checks two or more properties and return the first one that is not null or blank. Or even if one property is true, then display another property. And have you ever made a static function that displays a date in the correct format. I certainly have. The scope of this code is to make life easier.
I extended the EPiServer:property WebControl. This control takes,in its most basic mode, a propertyname and then displays that property on the page. If the property is on the CurrentPage and you are a editor you can edit it with dope. But you can separate different propertyname's by | so if the first one is null or blank the second one is used. The method will also find field,method and property on the active object. You can even drill down with .(dot) and if you drill down inside a pagereference you will get the reference page to work on.
I also have added some build in functions like StripHtml which will remove html from the text and have input how many characters that should be displayed. PropertyCheckName will check that value against CheckValue, and if the are equal Itera:Property will be shown, else it will be blank.
<Itera:Property
PropertyName="Heading|PageName"
AddFirst="<h2>"
AddLast="</h2>" ID="Property2" runat="server" />
<Itera:Property
PropertyName="Changed|Created:ToString(dd.MM.yyyy)"
PropertyCheckName="ShowDate"
CheckValue="true"
AddFirst="<i>("
AddLast=")</i>" ID="Property1" runat="server" />
<Itera:Property
PropertyName="MainIntro|PageParentLink.MainIntro:StripHtml(100)"
AddFirst="<strong>"
AddLast="</strong>" ID="Property7" runat="server" />
Using ITemplate
Often you want to display something more. Therefore I have added some ITemplate too Itera:Property. elements inside {element} will be evaluate the same was as PropertyName. if the current {element} is null/empty it will be removed. this version only handles string replacement inside the ITemplate. if you need a property add it inside the ITemplate.
Since the PropertyName is empty the the webcontrol will be visible. if it for instance was connected to a property that was null/blank then the hole control would have been blank.
<Itera:Property runat="server" >
<HeaderTemplate><div></HeaderTemplate>
<ItemTemplate>
<a href="{PageExternalURL|LinkURL}"
title="{MainIntro:StripHtml2Attribute(100)}"
{PageTargetFrame.FrameName:UseFormat(target="[item]")}
>
{PageName}
<Itera:Property
PropertyName="Changed|Created:ToString(dd.MM.yyyy)"
AddFirst="<i>("
AddLast=")</i>" ID="Property1" runat="server" />
</a>
</ItemTemplate>
<FooterTemplate></div></FooterTemplate>
</Itera:Property>
Looping over objects
if the object evaluated by PropertyName is either a PropertyDataCollection, PageDataCollection,PageReferenceCollection,CategoryList or a IList the ItemTemplate will be added for each of these items. Inside that ItemTemplate its possible to use the keyword this to get the active current object. The SuppressEmpty will remove all text inside each ITextControl object the evaluator function has found if one element is null/empty
<Itera:Property PropertyName="Property"
SuppressEmpty="true" runat="server" EnableViewState="false" >
<HeaderTemplate><table border="1"></HeaderTemplate>
<ItemTemplate>
<tr >
<td>{this.Name}</td>
<td>{this.Value}</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</Itera:Property>
Using this on MultiProperty
Itera.MultiProperty is a property that can contains inner properties look at my blog post about it.
A MultiProperty Contact have sub properties Name,About,HomeAdr and WorkAdr. To be able to navigate and use these properties it is just to navigate with dot syntaxes. To get work email it is Contact.WorkAdr.Email
<Itera:Property PropertyName="Contact" runat="server" EnableViewState="false" >
<ItemTemplate>
<h2>{this.Name}</h2>
{this.About:UseFormat(<strong>[item]</strong>)}
<Itera:Property
PropertyName="this.WorkAdr.PropertyCollection"
SuppressEmpty="true" runat="server" EnableViewState="false" >
<HeaderTemplate><table border="1"><tr><th colspan="2">Work</th></tr></HeaderTemplate>
<ItemTemplate>
<tr >
<td>{this.Name}</td>
<td>{this.Value}</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</Itera:Property>
</ItemTemplate>
</Itera:Property>this rude example will produce output like this:
KeyNotes
You can dived PropertyName with | and first not null/blank statement will be used
You can apply format to the selected object with :
There are some build inn functions:
StripHtml (max nr of chars)
StripHtml2Attribute (max nr of chars)
UseFormat (format where [item] will be replaced with the value)
if the result object is a list then the item template will have that object with the this key
Where to download
This is part of the Itera.MultiProperty