Skip to content

Instantly share code, notes, and snippets.

@contensis
contensis / 0_reuse_code.js
Created April 1, 2014 07:39
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@contensis
contensis / webapi-caching.vbs
Created April 4, 2014 09:20
Web API Caching
// Set the page cache duration for the template to be 5 minutes
CurrentContext.Page.Cache.PageCacheDuration(300)
// Set the page cache duration for the template to be 2 minutes
CurrentContext.Page.Cache.StandardListCacheDuration(120)
@contensis
contensis / custom-cache.vbs
Created April 4, 2014 09:41
Custom Cache
' This example will hardcode a cache on every oage that uses a particular template
Response.Cache.SetCacheability(Web.HttpCacheability.Public)
Response.Cache.SetExpires(Now.AddSeconds(60))
Response.Cache.SetValidUntilExpires(True)
'We want all Querystring parameters to be cached individually.
Response.Cache.VaryByParams("*") = True
Response.Cache.SetVaryByCustom("browser")
@contensis
contensis / working-with-css.vbs
Created April 28, 2014 09:20
Working with CSS Files
' If the same URL is registered twice it will only output one reference.
' The URL is used as a key to prevent duplicates.
' Add a CSS file to the document head
CurrentContext.Page.CSS.Add("styles.css")
' Note on IEConditions: you can specify any version of IE, the examples below are used for illstration purposes and are not exhaustive
' Add a CSS file with an IECondition (target IE7)
CurrentContext.Page.CSS.Add("styles.css", IECondition.IsVersion(7))
@contensis
contensis / working-with-metadata.vbs
Created April 28, 2014 09:58
Working with Metadata
' Add a piece of metadata with name and content attributes
CurrentContext.Page.Metadata.Add("description", "My page description")
' Specify the character encoding for the document.
CurrentContext.Page.Metadata.Add(HttpEquiv.ContentType, "utf-8")
' Specify the preferred style sheet to use.
CurrentContext.Page.Metadata.Add(HttpEquiv.DefaultStyle, "style.css")
' Defines a time interval for the document to refresh itself.
@contensis
contensis / webapi-caching.vbs
Created May 20, 2014 14:22
Web API Caching
// Set the page cache duration for the template to be 5 minutes
CurrentContext.Page.Cache.PageCacheDuration(300)
// Set the page cache duration for the template to be 2 minutes
CurrentContext.Page.Cache.StandardListCacheDuration(120)
@contensis
contensis / simple-query.cs
Created May 20, 2014 14:23
Carry out a simple query with the Contensis Web API Search.
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
<p>Simple Search</p>
@{
// Standard properties are prefixed with 'Property_'
var query = Query.Where("Property_Title").Contains("news");
// The NodeFinder.Find() method will by default search from the root of the site.
@contensis
contensis / and-query.cs
Created May 20, 2014 14:24
How to create a query with an AND clause in the Web API Search.
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
<h1>Search Example</h1>
@{
// Queries can be easily chained.
var query = Query.Where("MD_ShowOnFrontPage").IsEqualTo("1").And("Property_DateCreated").IsGreaterThan("'12 Oct 2011'");
var nodes = new NodeFinder().Find(query);
}
@contensis
contensis / sub-queries.cs
Created May 20, 2014 14:29
How to create a query with a sub query in the Web API Search.
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
<h1>Simple Search</h1>
@{
var query = Query.Where("Property_Path").StartsWith("/Products/Books/").OrSubQuery(
SubQuery.Where("Property_Path").StartsWith("/Products/DVDs/").And("MD_ShowInListing").IsEqualTo("1")
);
@contensis
contensis / or-query.cs
Created May 20, 2014 14:30
How to create a query with an OR clause in Web API Search.
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
<h1>Search Example</h1>
@{
var query = Query.Where("Property_Path").StartsWith("/Products/Books/").Or("Property_Path").StartsWith("/Products/Toys/");
var nodes = new NodeFinder().Find(query);
}