Posts

Showing posts from February, 2020

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