Skip to content

Instantly share code, notes, and snippets.

@komainu85
komainu85 / Sitecore Search Configuration
Last active Aug 29, 2015
Custom search index configuration (Sitecore 7.2)
View Sitecore Search Configuration
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<CustomSearchConrig>
<!-- INDEXING STRATEGIES
Here is a list of the different indexing strategies that you can use. You can also combine these strategies to achieve what you want.
-->
<indexUpdateStrategies>
<!-- INTERVAL BASED INDEX REBUILD STRATEGY FOR CORE DATABASE
@komainu85
komainu85 / Sitecore Get Home Item Extension
Created Feb 18, 2015
Sitecore get home from SiteContext
View Sitecore Get Home Item Extension
public static Item HomeItem(this SiteContext site)
{
return Sitecore.Context.Database.GetItem(site.StartPath);
}
@komainu85
komainu85 / Get Membership User From Sitecore Account
Created Feb 18, 2015
Get Membership User From Sitecore Account
View Get Membership User From Sitecore Account
public static class SitecoreAccountExtensions
{
public static MembershipUser GetMembershipUser(this Account account)
{
return Membership.GetUser(account.Name);
}
}
View Sitecore Expand Tokens
Sitecore.Data.MasterVariablesReplacer replacer = Sitecore.Configuration.Factory.GetMasterVariablesReplacer();
Sitecore.Diagnostics.Assert.IsNotNull(replacer, "replacer");
replacer.ReplaceItem(item);
@komainu85
komainu85 / IsStandardValue
Created Feb 18, 2015
IsStandardValue Sitecore Computed Field
View IsStandardValue
public class IsStandardValue : IComputedIndexField
{
public object ComputeFieldValue(IIndexable indexable)
{
Item item = indexable as SitecoreIndexableItem;
return StandardValuesManager.IsStandardValuesHolder(item);
}
public string FieldName { get; set; }
@komainu85
komainu85 / Sitecore Item Template Comparer
Created Feb 18, 2015
Sitecore Item Template Comparer
View Sitecore Item Template Comparer
public class ItemTemplateComparer : IEqualityComparer<Item>
{
public bool Equals(Item x, Item y)
{
return x.TemplateID == y.TemplateID;
}
public int GetHashCode(Item obj)
{
return obj.TemplateID.GetHashCode();
@komainu85
komainu85 / Sitecore Get Image URL with Dimensions
Created Feb 24, 2015
Sitecore Get Image URL with Dimensions
View Sitecore Get Image URL with Dimensions
public static string GetImageUrl(this MediaItem mediaItem, int maxWidth = 0, int maxHeight = 0)
{
return GetMediaUrl(mediaItem) + CreateImageSizeQuery(maxWidth, maxHeight);
}
public static string GetMediaUrl(this MediaItem mediaItem)
{
var mediaUrl = MediaManager.GetMediaUrl(mediaItem);
return mediaUrl.Contains(MediaManager.MediaLinkPrefix)
@komainu85
komainu85 / Sitecore Content Search with Keywords
Created Feb 25, 2015
Sitecore Content Search with Keywords
View Sitecore Content Search with Keywords
public SearchResult<SearchItem> Search(string keywords)
{
using (var context = Sitecore.ContentSearch.ContentSearchManager.GetIndex(_searchIndex).CreateSearchContext())
{
var queryable = context.GetQueryable<SearchItem>();
Expression<Func<SearchItem, bool>> filters;
filters = GetKeywordFilters(keywords);
queryable = queryable.Where(filters);
@komainu85
komainu85 / PageCode.ts
Last active Aug 29, 2015
Sitecore SPEAK PageCode TypeScript
View PageCode.ts
import Speak = require("sitecore/shell/client/Speak/Assets/lib/core/1.2/SitecoreSpeak");
class PageCode extends Speak.PageCode {
initialize() {
}
}
Sitecore.Speak.pageCode(["bootstrap", "scPipeline"], new PageCode());
@komainu85
komainu85 / Bind Sitecore components to DataSource
Last active Aug 29, 2015
Auto bind Sitecore components to DataSource (Forked from Jamie Little)
View Bind Sitecore components to DataSource
public void BindDatasourceToSitecoreControls()
{
BindDatasourceToSitecoreControls(DataSourceItem);
}
public void BindDatasourceToSitecoreControls(Item dataSource)
{
if (Controls.Count > 0)
{
BindControls(this.Controls, dataSource);