Skip to content

Instantly share code, notes, and snippets.

@DaveGoosem
DaveGoosem / switchSitecoreContext.cs
Created May 1, 2014 13:41
Switch Sitecore context
using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext("shell")))
{
//perform actions
}
@DaveGoosem
DaveGoosem / SEO Friendly URLs - Web.Config Changes
Created February 8, 2013 04:43
Change 1: To have spaces be changed to hyphens, you need to edit Sitecore’s web.config and tell it to replace ” ” with “-”. In the “encodeNameReplacements” node, we add the final “replace” node seen below. Change 2: Because of this change, whenever someone requests a page with a hyphen, Sitecore is going to assume that it needs to be translated …
<!-- Change 1 -->
<encodenamereplacements>
<replace mode="on" find="&amp;" replaceWith=",-a-," />
<replace mode="on" find="?" replaceWith=",-q-," />
<replace mode="on" find="/" replaceWith=",-s-," />
<replace mode="on" find="*" replaceWith=",-w-," />
<replace mode="on" find="." replaceWith=",-d-," />
<replace mode="on" find=":" replaceWith=",-c-," />
<replace mode="on" find=" " replaceWith="-" />
</encodenamereplacements>
@DaveGoosem
DaveGoosem / dom-traversal.js
Created May 7, 2013 15:25
jQuery DOM Traversal
//returns all instances of the selector within find();
$("#vacations").find(".america");
//returns only the first of all similar DOM items
$("#vacations li").first();
//returns only the last of all similar DOM items
$("#vacations li").last();
//returns the 'next' similar DOM item to the one you previsouly specified.
@DaveGoosem
DaveGoosem / web.config
Created May 8, 2013 01:13
Set the Default HTML Editor in Sitecore to be 'Rich Text Full'
<!-- HTML EDITOR DEFAULT PROFILE
Path to the default html editor profile.
Default value: /sitecore/system/Settings/Html Editor Profiles/Rich Text Default
-->
<setting name="HtmlEditor.DefaultProfile" value="/sitecore/system/Settings/Html Editor Profiles/Rich Text Full"/>
@DaveGoosem
DaveGoosem / manipulatingDom.js
Created May 8, 2013 08:08
Manipulating the DOM
//lets you add something in the DOM directly after the DOM element you target.
.append()
//lets you add something in the DOM directly before the DOM element you target.
.prepend()
.after()
//lets you place something in the DOM directly above, at the same level the item you target.
.before()
@DaveGoosem
DaveGoosem / traversingAndFiltering.js
Created May 8, 2013 11:06
Traversing and Filtering
/*allows you to filter SOME of a given element with simlar components
based upon what those some have that others don't.
For example: if you had
<ul>
<li class="vacation onsale"></li>
<li class="vacation onsale"></li>
<li class="vacation"></li>
<li class="vacation"></li>
@DaveGoosem
DaveGoosem / web.config
Created May 8, 2013 23:36
Pick up directory for IIS website using web.config
<!--
After the </system.web> closing tag, insert the contents below between the <system.net> tags.
-->
</system.web>
<system.net>
<mailSettings xdt:Transform="Replace">
<smtp from="test@test.com.au" deliveryMethod="SpecifiedPickupDirectory">
<network host="localhost" />
<specifiedPickupDirectory pickupDirectoryLocation="d:\smtp\" />
</smtp>
@DaveGoosem
DaveGoosem / encodeURI.js
Created May 9, 2013 01:20
Encode script for XSS testing
/*
Use the encodeURIComponent to allow you to switch out all characters to their encoded
values. You can then attempt to inject into forms using the encoded values.
Example Below:
*/
//in Web Tools (F12 in chrome), in the console, enter something like this:
encodeURIComponent('<script>alert("please soemthing")</script>')
//will return value like this which you can copy/paste into input fields on site to test
@DaveGoosem
DaveGoosem / KBListingML.ascx
Created May 10, 2013 05:54
Example Sitecore control using datasources and Multilists Note: Multilists need to use Sitecore Item IDs find items.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="KnowledgeBaseListing.ascx.cs" Inherits="DigiconNew.layouts.Sublayouts.Controls.KnowledgeBaseListing" %>
<% foreach (var kbcategory in KBCategories)
{
%>
<div class="article">
<div class="article-title">
<h3>
<a href='<%= GetURL(kbcategory) %>'><%= kbcategory["Article Title"]%></a>
</h3>
@DaveGoosem
DaveGoosem / clearSitecoreCache.cs
Created May 14, 2013 03:17
Clearing Sitecore Cache
Database db = new Database("web");
if (ID.IsID(id))
{
ID itemID = new ID(id);
//clear data cache
db.Caches.DataCache.RemoveItemInformation(itemID);
//clear item cache
db.Caches.ItemCache.RemoveItem(itemID);