Skip to content

Instantly share code, notes, and snippets.

View PetersonDave's full-sized avatar

David Peterson PetersonDave

View GitHub Profile
@PetersonDave
PetersonDave / gist:4948852
Last active January 2, 2019 23:54
Checking Sitecore field type via FieldTypeManager.GetField()
var field = item.Fields[_fieldId];
var type = FieldTypeManager.GetField(field);
if (type is LinkField)
{
...
}
if (type is InternalLinkField) // such as drop tree controls
{
...
@PetersonDave
PetersonDave / gist:6800139
Created October 2, 2013 20:36
Prevent users from submitting forms twice in Sitecore's Web Forms for Marketers.
using System;
using Sitecore.Form.Core.Renderings;
using Sitecore.Form.Web.UI.Controls;
namespace Custom.Form.Web.UI.Controls
{
public class PreventDoubleClickFormRender : FormRender
{
// disables submit button if group validator for submit is valid
private const string PreventDoubleSubmitJs = @"function disableSubmitButton(groupValidator, submitButton) {{ $(submitButton).disabled = Page_ClientValidate(groupValidator);}}";
@PetersonDave
PetersonDave / gist:5096452
Last active January 7, 2017 12:57
Web forms for marketers redirect assumes the success page is relative to the form item in the tree (template: /sitecore/templates/Web Forms for Marketers/Form). When this is not the case, wffm builds a redirect URL which is not valid. Since the success page is defined using a general link field, we don't have a Guid to lookup the actual success …
/*
Extends: Sitecore.Form.Core.Pipelines.FormSubmit
forms.config needs to be updated to:
<successAction>
<processor type="MyCustom.Pipelines.SuccessRedirect, MyLibrary"/>
<processor type="Sitecore.Form.Core.Pipelines.FormSubmit.FormatSuccessMessage, Sitecore.Forms.Core"/>
</successAction>
*/
@PetersonDave
PetersonDave / gist:7636456
Created November 25, 2013 04:39
Define the routes - templateUrls are all Sitecore items! Sitecore now serves our views :)
function getRoutes() {
return [
{
url: '/profiles',
config: {
templateUrl: 'Views/allprofiles',
controller: 'allprofiles'
}
}, {
url: '/profiles/:profileId',
@PetersonDave
PetersonDave / gist:7636551
Created November 25, 2013 04:51
routing with Sitecore item version number
function getRoutes() {
return [
{
url: '/profiles',
config: {
templateUrl: 'Views/allprofiles?v=4',
controller: 'allprofiles'
}
}, {
url: '/profiles/:profileId',
@PetersonDave
PetersonDave / gist:7636427
Created November 25, 2013 04:35
Sitecore rendering for view within an Angular app
<%@ Control Language="c#" AutoEventWireup="true" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<div data-ng-controller="allprofiles as vm">
<p><a class="btn btn-primary btn-lg" ng-click="vm.load();">Load Data</a></p>
<div class="row" ng-repeat="profile in vm.repository">
<div class=" col-md-1">
<a class="btn btn-danger btn-small" href="#profiles/{{profile.ID}}">Edit</a>
</div>
<div class="col-md-1">{{profile.DisplayName}}</div>
<div class="col-md-6">{{profile.ID}}</div>
@PetersonDave
PetersonDave / gist:7636365
Created November 25, 2013 04:27
PartialView used as a layout for our Angular views in Sitecore
<%@ Page language="c#" Codepage="65001" AutoEventWireup="true" %>
<%@ OutputCache Location="None" VaryByParam="none" %>
<sc:FieldRenderer ID="FieldRenderer1" runat="server" FieldName="details" />
<sc:placeholder key="main" runat="server" />
@PetersonDave
PetersonDave / gist:7636020
Created November 25, 2013 03:46
Setting Sitecore Item Web API permissions
app.config(
...
'$httpProvider', function($httpProvider) {
$httpProvider.defaults.headers.put = { 'X-Scitemwebapi-Username': 'admin' };
$httpProvider.defaults.headers.put = { 'X-Scitemwebapi-Password': 'b' };
});
@PetersonDave
PetersonDave / gist:7635829
Created November 25, 2013 03:24
Angular view for populating based on controller allprofiles
<div data-ng-controller="allprofiles as vm">
<p><a class="btn btn-primary btn-lg" ng-click="vm.load();">Load Data</a></p>
<div class="row" ng-repeat="profile in vm.repository">
<div class=" col-md-1">
<a class="btn btn-danger btn-small" href="#profiles/{{profile.ID}}">Edit</a>
</div>
<div class="col-md-1">{{profile.DisplayName}}</div>
<div class="col-md-6">{{profile.ID}}</div>
</div>
@PetersonDave
PetersonDave / gist:7635778
Created November 25, 2013 03:17
Angular controller calling our factory profileService to pull Sitecore items
(function () {
'use strict';
// Controller name is handy for logging
var controllerId = 'allprofiles';
// Define the controller on the module.
// Inject the dependencies.
// Point to the controller definition function.
angular.module('app').controller(controllerId,