Skip to content

Instantly share code, notes, and snippets.

@ps-team
ps-team / CustomCodeSnippets.vbs
Created October 27, 2017 14:16
Assorted Custom Code Snippets - see comments for details
////////////////////////////////////////////////////////
***Set a datafilter on a control using the current folder***
Dim SectionFolderID As Integer
SectionFolderID = CurrentNode.Data.Property_F_ID
Dim DataFilter As New CMS_API.Data.DataFilterExpression("", CMS_API.Data.DataFilterFunction.Custom, "(Property_F_ID LIKE " & SectionFolderID & ")")
FAQListing.DataFilters.Add(DataFilter)
////////////////////////////////////////////////////////
@ps-team
ps-team / ResolvingSynchronisedNodes.cshtml
Created October 27, 2017 10:13
Resolve a list of master pages from a listing of nodes - finds the most local version of the node by checking for other nodes in top level parent folder that have the same SynchronisationSourceMasterContentID. Notes: Make sure you output SynchronisationSourceMasterContentID by ticking the box in Project Settings > Project > Metadata. Then to for…
@functions {
public ContentNode ResolveSynchedLink(ContentNode link)
{
// if this a synched link then change path to the most local synched version
if (link.Data.SynchronisationSourceMasterContentID >= 0)
{
int masterPageContentID = link.Data.SynchronisationSourceMasterContentID;
@ps-team
ps-team / Append stylesheet to iframe.js
Created October 27, 2017 10:07
Append stylesheet to iframe contents (e.g. Twitter widget) - this is filthy, but it works well when no other option is available.
$(document).ready(function(){
setTimeout(function() {
var iframe = document.getElementsByTagName('iframe')[0],
iframeDoc = iframe.contentWindow.document;
var otherhead = iframeDoc.getElementsByTagName("head")[0];
var css = document.createElement("link");
css.type = "text/css";
css.rel = "stylesheet";
css.href = "/SiteElements/Stylesheets/twitter-widget.css";
@ps-team
ps-team / LocalViewMenuC#.cshtml
Created October 27, 2017 10:06
A razor view that mimics the functionality of our local view menu control buts outputs semantic markup and classes that allow for easier and more flexible styling
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
<ul class="sys_menu">
@{
AppContext.Current.Page.Scripts.RegisterJQuery();
if(CurrentNode != null) {
//This will be replaced by a function in future releases
var currentFolder = CurrentNode.Parent;
var currentDepth = CurrentNode.Parent.Depth;
@ps-team
ps-team / a-z.cshtml
Created October 27, 2017 10:05
A-Z listing (c#) - will need a bit of work, but the basics are in there
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
@{
var jobItemsQuery = Query.Where("SC_T_ID").IsEqualTo("-2356380").OrderBy("Property_Title").Ascending; /* Template and ordering */
var jobItems = new NodeFinder().Find(jobItemsQuery);
var utils = new CMS_API.Common.BaseUtilities();
string alphabet = "abcdefghijklmnopqrstuvwxyz"; /* alphabet! - there are better ways to do this, however it seems overcomplicated and this is just simple. */
string letter = Request.QueryString["letter"];
@ps-team
ps-team / EventsCalandarCarousel.cshtml
Created October 27, 2017 10:04
Events Calendar carousel for the next 12 months of events - used carouFredSel.js
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
@{
/* We'll start by getting the current month */
var currentMonth = DateTime.Now.ToString("MMM");
/* Now, we'll get the template by ID for the events records */
var eventsQuery = Query.Where("SC_T_ID").IsEqualTo("-212");
var eventItems = new NodeFinder().Find(eventsQuery);
@ps-team
ps-team / NewsCatList.cshtml
Created October 27, 2017 10:03
List of news categories that link through to the listing template under the current top folder.
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
@{
// This could use the GetByKey() method instead.
var node = CurrentContext.Taxonomy.GetByPath("StructuredContent/newscategories/", TaxonomySortOrder.Alphabetical);
var listingPath = "";
string topFolderId = CurrentNode.Data.Property_TopFolderId.ToString();
@ps-team
ps-team / BasicDataFilter.vbs
Created October 27, 2017 10:03
Filter a listing control to the current top folder
[ControlID].DataFilters.Add(New DataFilterExpression("Property_TopFolderId", CMS_API.Data.DataFilterFunction.EqualTo, Property_TopFolderId))
@ps-team
ps-team / AddIe7Stylesheet.vbs
Created October 27, 2017 10:02
Add ie stylesheet in custom code using the WebApi
Dim IsIe7 As IECondition = IsIe7.IsVersion(7)
CurrentContext.Page.CSS.Add("/Zengenti-Test-Folder-2013-Re-Design/SiteElements/Stylesheets/903-ie7.css", IsIe7)
'For more option other that .IsVersion see http://support.contensis.co.uk/Development/WebAPI/Reference/Contensis.Framework.Web-Namespace/IECondition-Class/IECondition-Methods/IECondition-Methods.aspx
@ps-team
ps-team / TopMenuFromFolder.cshtml
Created October 27, 2017 10:02
A top menu razor that is set using a folder of hyperlink content types. Allows restricted editing by certain user groups. Also has data attribute for target node ID for use with an ajax mega menu.
@using Contensis.Framework.Web;
@using Contensis.Framework.Web.Search
<ul id="menu" class="sys_navbar">
<li class="sys_topnav"><a class="sys_home" href="/" title="Home"><img src="/SiteElements/img/homeicon.png" width="23" height="48" alt="Home" /></a></li>
@{
var query = Query.Where("Property_F_ID").IsEqualTo("48"); // Add ID of folder to target here
var pages = new NodeFinder().Find(query);
var linkClass = "";