Skip to content

Instantly share code, notes, and snippets.

Avatar

Janae Cram naepalm

View GitHub Profile
@naepalm
naepalm / Pagination.cshtml
Last active Dec 22, 2021
A "quick & easy" razor pagination to plug into an Umbraco View, Partial View, or Macro
View Pagination.cshtml
@{
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 Oct 14, 2019
People say you only die once, but Bryce Kenoyer knows the unlucky ones have a chance to die twice.
View TheEnd.md

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 Oct 8, 2019
An example of different ways to code the Umbraco FAQ Package's content.
View FAQListing.cshtml
@using FAQ
@inherits UmbracoTemplatePage
@{
Layout = null;
}
<h1>@Model.Content.Name</h1>
<h2>Render All FAQ Items</h2>
@naepalm
naepalm / ContactForm.cs
Created Dec 3, 2015
Contact Form for Umbraco with a Departments dropdown list. Assumes the dropdown list is NestedContent on the selected Email Template.
View ContactForm.cs
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
{
View AutoMapperSetup.md

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 Jan 10, 2019
A set of useful extension methods for Umbraco properties.
View ContentExtensions.cs
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 Jan 8, 2019
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.
View MarkdownConverter.gs
/*
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 Aug 31, 2018
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!
View RadioButtonValueConverter.cs
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 Jul 20, 2018
Checks to see if a grid has a specific row.
View HasGridRow.cs
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 Feb 8, 2017
Get all dictionary items for a language on a site and spit them out in an API Controller.
View DictionaryController.cs
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
{