Skip to main content

Posts

Recent posts

Umbraco 9 - Strip HTML and Truncate text output

Umbraco 9 - Strip HTML and Truncate text/html output.  The code below can be used for truncating/shortening text and striping out HTML tags in Umbraco 9 to display shorter text useful for landing pages. Instructions:  Replace "bodyText" with the reference to the property you would like to truncate. Code: Example output:

Umbraco 9 - Left hand sub page navigation code snippet.

Umbraco 9 - Left hand sub page navigation code C# RAZOR snippet.  The code below can be used for left hand navigation in Umbraco 9 to create left hand/sub page navigation.  Instructions:  Create a partial _leftHandNavigation  Reference the partial in your Umbraco template, like this: @Html.Partial("_leftHandNavigation") Code: Example output:

Umbraco 8 Pagination

Umbraco 8 Pagination / Paging: @inherits Umbraco.Web.Mvc.UmbracoViewPage @{     Layout = "master.cshtml";         var pageSize = 8;     if(Model.HasValue("numberOfItemsPerPage")){     pageSize = Model.Value<int>("numberOfItemsPerPage");}         var page = 1; int.TryParse(Request.QueryString["page"], out page);     @* This line assumes you have a property called lastUpdated*@     var items = Model.Children().OrderByDescending(x => x.Value("lastUpdated"));     @* Remove the line above and use this line to keep it simple *@     @* var items = Model.Children()); *@             var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);     if (page > totalPages)     {         page = totalPages;     }     else if (page < 1)     {         page = 1;     } } @foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize))             {            <a href="@item.