Mark Downie Blog
7 FOLLOWERS
I am Mark Downie a web developer who uses the Umbraco CMS. On my blog, I share information about Umbraco's text output, pagination, date formatting, Navi hide, and many more!
Mark Downie Blog
7M ago
DateTime parsedDate = DateTime.Parse(item.Value<DateTime>("testimonailDate").ToString("dd MMMM yyyy"));
var daysPast = (DateTime.Today - parsedDate).TotalDays;
@if(daysPast == 1)
{
<span >@daysPast day ago</span> ..read more
Mark Downie Blog
7M ago
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 ..read more
Mark Downie Blog
7M ago
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:
https://www.buymeacoffee.com/markdevelopment/umbraco-side-bar-left-hand-navigation ..read more
Mark Downie Blog
7M ago
Umbraco 8 Convert Line Breaks for TextArea Example
@Html.ReplaceLineBreaksForHtml(@Model.Value("lineOne").ToString ..read more
Mark Downie Blog
7M ago
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("lastUpda ..read more
Mark Downie Blog
7M ago
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 ..read more
Mark Downie Blog
7M ago
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> ..read more
Mark Downie Blog
7M ago
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> ..read more
Mark Downie Blog
7M ago
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 applicatio ..read more
Mark Downie Blog
7M ago
<p>@Umbraco.StripHtml(@Umbraco.Truncate(@Umbraco.Content(1067).bodyText, 300))</p> ..read more