Skip to content

Instantly share code, notes, and snippets.

View naepalm's full-sized avatar

Janae Cram naepalm

View GitHub Profile
@naepalm
naepalm / FAQListing.cshtml
Last active October 8, 2019 23:45
An example of different ways to code the Umbraco FAQ Package's content.
@using FAQ
@inherits UmbracoTemplatePage
@{
Layout = null;
}
<h1>@Model.Content.Name</h1>
<h2>Render All FAQ Items</h2>
@naepalm
naepalm / Editors\Base.cshtml
Last active October 30, 2017 20:20
Grid view & controls for Skybrud's strongly typed models with Responsive BP
@model GridControl
@using Grid.Web
@using Skybrud.Umbraco.GridData
@try
{
<text>@Html.Partial(Model.EditorView(), Model)</text>
}
catch (Exception ex) {
<pre>@ex.ToString()</pre>
@naepalm
naepalm / TextPage.cshtml
Last active March 21, 2016 17:22
Basic text page template content with headings & general content for styling
@inherits UmbracoViewPage<TextPageViewModel>
@using Client.Web.Models.ViewModels
@{
Layout = "OneColumn.cshtml";
}
<section id="primary" class="col-s-8 offset-s-2">
@*Model.BodyText*@
<h1>Heading 1</h1>
@naepalm
naepalm / Pagination.cshtml
Last active December 22, 2021 12:29
A "quick & easy" razor pagination to plug into an Umbraco View, Partial View, or Macro
@{
var pageSize = 8;
if(Model.Content.HasValue("numberOfItemsPerPage")){
pageSize = Model.Content.GetPropertyValue<int>("numberOfItemsPerPage");}
var page = 1; int.TryParse(Request.QueryString["page"], out page);
var items = Umbraco.TypedContent(Model.Content.Id).Children.Where(x => x.DocumentTypeAlias == "exampleAlias" && x.IsVisible()).OrderByDescending(x => x.CreateDate);
var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);
if (page > totalPages)
namespace Client.Web.Models
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Buzz.Hybrid;
using Buzz.Hybrid.Models;
@naepalm
naepalm / MediaSave.cshtml
Last active December 3, 2015 19:38
A little razor template snippet that re-saves/republishes all media in Umbraco
@using Umbraco.Core.Models;
@{
var mediaService = ApplicationContext.Current.Services.MediaService;
SaveMedias(mediaService.GetRootMedia().ToList());
}
@functions
{
@naepalm
naepalm / ContactForm.cs
Created December 3, 2015 19:49
Contact Form for Umbraco with a Departments dropdown list. Assumes the dropdown list is NestedContent on the selected Email Template.
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Umbraco.Core.Models;
using Umbraco.Web;
namespace Forms.Web.Models
{
public class ContactForm
{
@naepalm
naepalm / ContentExtensions.cs
Last active January 10, 2019 01:32
A set of useful extension methods for Umbraco properties.
namespace Client.Web
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Models;
using Newtonsoft.Json;
using Umbraco.Core.Models;
public class CacheService : ICacheService
{
private readonly MemoryCache _memoryCache = new MemoryCache("Cache.Key");
public void Add<T>(T cacheObject, string key)
{
var cacheItemPolicy = new CacheItemPolicy
{
AbsoluteExpiration = DateTimeOffset.Now.AddHours(24)
};
@naepalm
naepalm / Helpers.js
Last active August 3, 2017 22:46
Helper functions for react, such as price currency formatting.
var Helpers = {
/**
* @function formatMoney
* @param {number} n - The number to be formatted
* @param {string} d - The character to be used for the decimal. Defaults to ".".
* @param {string} t - the character to be used for the thousands separator. Defaults to ",".
* @param {int} c - the number of decimal places. Defaults to 2.
* @returns {string}
* @description Formats a number to a price
*/