Created
January 6, 2011 00:00
-
-
Save gabesumner/767266 to your computer and use it in GitHub Desktop.
Helper tool for truncating text based on a Length of characters in a Sitefinity Widget Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Control Language="C#" %> | |
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %> | |
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %> | |
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> | |
<%@ Register TagPrefix="cc1" Namespace="SitefinityWebApp.Tools" Assembly="SitefinityWebApp" %> | |
<telerik:RadListView ID="eventsList" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false"> | |
<LayoutTemplate> | |
<ul class="sfeventsList sfeventsListTitleCityDateContent"> | |
<asp:PlaceHolder ID="ItemsContainer" runat="server" /> | |
</ul> | |
</LayoutTemplate> | |
<ItemTemplate> | |
<li class="sfeventListItem"> | |
<div class="sfeventDateSummary"> | |
<div class="sfeventDay"><%# Eval("EventStart", "{0:ddd}")%></div> | |
<div class="sfeventDate"><%# Eval("EventStart", "{0:dd}")%></div> | |
<div class="sfeventMonth"><%# Eval("EventStart", "{0:MMM}")%></div> | |
</div> | |
<h3 class="sfeventTitle"> | |
<sf:DetailsViewHyperLink ID="DetailsViewHyperLink1" TextDataField="Title" ToolTipDataField="Description" runat="server" /> | |
</h3> | |
<div class="sfeventMetaInfo"> | |
<sf:FieldListView ID="where" runat="server" Text="{0} | " Properties="City" /> | |
<sf:FieldListView ID="EventsDates" runat="server" /> | |
</div> | |
<div class="sfeventContent"> | |
<cc1:Truncate Text='<%# Eval("Content")%>' WordLength="200" runat="server" /> | |
<sf:DetailsViewHyperLink ID="DetailsViewHyperLink2" Text="Read more" runat="server" /> | |
</div> | |
</li> | |
</ItemTemplate> | |
</telerik:RadListView> | |
<sf:Pager id="pager" runat="server" NavigationMode="Links"></sf:Pager> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ul.sfeventsList | |
{ | |
padding: 0; | |
margin: 0; | |
} | |
ul.sfeventsList h3.sfeventTitle | |
{ | |
border-bottom: 1px solid #707070; | |
font-size: 1.5em; | |
padding-bottom: 0.5em; | |
margin: 0 0 0.25em 3.5em; | |
} | |
ul.sfeventsList h3.sfeventTitle a | |
{ | |
color: Black; | |
text-decoration: none; | |
} | |
.sfeventsList .sfeventDateSummary | |
{ | |
color: White; | |
float: left; | |
padding: 0.5em; | |
margin: 0 1em 0 0; | |
background-color: #464646; | |
text-align: center; | |
clear: both; | |
width: 3.5em; | |
} | |
.sfeventsList .sfeventDateSummary .sfeventDay | |
{ | |
font-size: 1.25em; | |
} | |
.sfeventListItem | |
{ | |
margin-bottom: 1.5em; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.UI.WebControls; | |
using Telerik.Sitefinity.Data.Summary; | |
namespace SitefinityWebApp.Tools | |
{ | |
public class Truncate : Literal | |
{ | |
/// <summary> | |
/// Determines how many words the Text will be truncated to. Sitefinity will preserve the HTML. | |
/// </summary> | |
public int WordLength | |
{ | |
get | |
{ | |
return _wordlength; | |
} | |
set | |
{ | |
_wordlength = value; | |
} | |
} | |
/// <summary> | |
/// This is used for backwards compatibility. The first version of Truncate only had the Length property. | |
/// </summary> | |
public int Length | |
{ | |
get | |
{ | |
return WordLength; | |
} | |
set | |
{ | |
WordLength = value; | |
} | |
} | |
protected override void CreateChildControls() | |
{ | |
var settings = new SummarySettings(SummaryMode.Words, WordLength, false); | |
Text = SummaryParser.GetSummary(Text, settings); | |
base.CreateChildControls(); | |
} | |
private int _wordlength = 20; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment