Posts

Showing posts from 2020

Umbraco 8 Convert Line Breaks for TextArea Example

 Umbraco 8  Convert Line Breaks for TextArea Example @Html.ReplaceLineBreaksForHtml( @Model.Value("lineOne") .ToString() )

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.

Umrbaco 8 Date Formatting

Format a Date in Umbraco 8 @(Model.Value<DateTime>("publicationDate").ToString("dd MMMM yyyy")) or in a foreach loop: @(item.Value<DateTime>("publicationDate").ToString("dd MMMM yyyy"))

Umbraco 8 Umbraco Navi Hide - Hide Page in foreach

Example of using umbracoNaviHide in Umbraco 8: @foreach (var item in @Model.AncestorOrSelf(3).Children() .Where(x => x.IsVisible())) { }

Umbraco 8 OrderBy a collection by a Custom Field Such as a Date

This is a snippet for Umbraco 8  to Order a collection by a Custom Field Such as a Date. @{     var selection = Umbraco.Content(Model.Id)     .ChildrenOfType("publication")     .Where(x => x.IsVisible())     .OrderBy( x => x.Value("publicationDate")); } @foreach (var item in selection.Take(1)) {      <h2><a href="@item.Url" title="@item.Name">@item.Name</a></h2> }

Umbraco 8 Umbraco Strip and Umbraco Truncate - usefull for landing pages

Umbraco 8: <p>@Html.StripHtml(@Html.Truncate(@item.Value("bodyText").ToString(), 65))   (Thanks to A.S for the above)   Umbraco 7:    <p>@Umbraco.StripHtml(@Umbraco.Truncate(@Umbraco.Content(1067).bodyText, 300))</p>

Umbraco 8 Metadata Snippet, keywords, meta title.

Umbraco 8 Metadata Snippet, keywords, meta title, meta description: The following is a snippet that may help with generating metadata. I created this as a partial and added it to the Main Template. If the metadata fields are not filled in on the backend by the editor, they are generated from the Page Name and the Name of the Website (applicationName). ---- In the example the backend meta fields are called: "metaTitle"   (textstring) "metaDescription"   (textstring) "metaKeywords" (tags) ---- @inherits Umbraco.Web.Mvc.UmbracoViewPage @{     var applicationName = "My Website Name"; } @if(Model.HasValue("metaTitle")){     <title>@Model.Value("metaTitle")</title> }  else {     if(Model.Id == Umbraco.ContentAtRoot().FirstOrDefault().Id)     {         <title>@applicationName</title>     }     else     {         <title>@Model.Name | @applicationName</title>     } } @if(Model.HasValue