Skip to content

Instantly share code, notes, and snippets.

View naepalm's full-sized avatar

Janae Cram naepalm

View GitHub Profile
@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)
@naepalm
naepalm / TheEnd.md
Last active October 14, 2019 01:03
People say you only die once, but Bryce Kenoyer knows the unlucky ones have a chance to die twice.

The Witching Hour, October 12, 2019

She spent an entire five minutes standing in the woods a short walk from her house, screaming. It doesn't matter. Screaming her pain into the void has only resulted in something happening once over the last two years she's done it when the night has been particularly bad. And in that moment, there had been a gorgon. But tonight, with the worst news she's had in three years, Bryce needed to do something - even if it's entirely futile - to let it out.

That was a half an hour ago. Now, she's sitting in the treehouse, burrowed in her insulated sleeping bag with half a bottle of whiskey left and no end to the misery. But a crisp, clear October night means the stars are out and beautiful against the dark sky. So Bryce stares at it as she takes pulls from the bottle, body warm but face cold against the air, and she remembers.


Early Evening, January 17, 2016

@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 / 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
{

How to set up ModelsBuilder & AutoMapper on a Project

AutoMapper is used to map the ModelsBuilder Api to Umbraco ViewModels. Dave Woestenborghs has written an excellent article on 24 Days that you can read for more information. This step-by-step is basically a paired down version of his article and a heads up for gotchas we encountered when setting up our project.

Step 1: Install the Visual Studio Extension for ModelsBuilder

(If this isn't your first project using this method, you already have this installed, so don't worry about it!)

Download and Install Stephan's custom ModelsBuilder tool for VS:

@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;
@naepalm
naepalm / MarkdownConverter.gs
Created January 8, 2019 18:19
Converts a Google Doc into Markdown and e-mails it to the account attached to the document. Open a doc and go to Tools > Script Editor then paste this code in and run it.
/*
Usage:
Adding this script to your doc:
- Tools > Script Manager > New
- Select "Blank Project", then paste this code in and save.
Running the script:
- Tools > Script Manager
- Select "ConvertToMarkdown" function.
- Click Run button.
- Converted doc will be mailed to you. Subject will be "[MARKDOWN_MAKER]...".
@naepalm
naepalm / RadioButtonValueConverter.cs
Created August 31, 2018 15:30
Converts the core radio button automagically with ModelsBuilder from the value Id to the prevalue string. This does not use Dependency Injection, but it does work, so feel free to use it if you'd like!
using System;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web;
namespace Offroadcode.Web.PropertyConverters
{
class RadioButtonValueConverter : PropertyValueConverterBase, IPropertyValueConverterMeta
{
@naepalm
naepalm / HasGridRow.cs
Last active July 20, 2018 15:06
Checks to see if a grid has a specific row.
public static bool HasGridRow(this GridDataModel model, string rowName)
{
if (model.Sections.Any())
{
foreach (var section in model.Sections)
{
if (section.HasRows)
{
foreach (var row in section.Rows)
{
@naepalm
naepalm / DictionaryController.cs
Created February 8, 2017 18:08
Get all dictionary items for a language on a site and spit them out in an API Controller.
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Web;
using Umbraco.Web.WebApi;
namespace Olympic.Web.Controllers.Api
{
public class DictionaryController : UmbracoApiController
{