Skip to content

Instantly share code, notes, and snippets.

@ps-team
ps-team / Distinct list of categories.cshtml
Created October 27, 2017 09:50
Generate a **distinct** list of 'categories' assigned to a set of nodes. This code loops through a set of nodes, creates an array from the categories on each node, then we get only the distinct ones. This array can then be looped through again to build a list of your categories.
@using Contensis.Framework.Web.Search;
@{
var query = Query.Where("Property_Path").StartsWith("/connect/blog/").And("Property_AuthorID").IsEqualTo(authorId.ToString()).OrderBy("Property_Title");
var nodes = new NodeFinder().Find(query, selectCount: 20);
string fulltagslist = "";
}
@foreach(var node in nodes)
{
@ps-team
ps-team / news list with category filter
Created October 27, 2017 09:51
News list with category filtering Requires meta data for categories to be added to the page so editors can control categories shown.
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
@{
// Get category value from url to filter results with
var catFilter = Request.QueryString["TaxonomyKey"];
// Get news articles
var newsArticlesQuery = Query.Where("SC_T_ID").IsEqualTo("-2875009").And("Property_TaxonomyCategories").Contains(catFilter).OrderBy("Property_DatePublished").Descending;
var newsArticles = new NodeFinder().Find(newsArticlesQuery, selectCount:8);
@ps-team
ps-team / Skip and Take
Created October 27, 2017 09:51
Group items and wrap in a div in Razor using Skip and Take
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search;
@{
var relatedContent = CurrentNode.RelatedNodes();
}
@if (relatedContent.Count >= 1){
for (var i = 0; i < relatedContent.Count; i += 3)
{
@ps-team
ps-team / SendAnEmail.cs
Created October 27, 2017 09:51
Send an email to an email address using the EmailHost set against the publisher. You could create a text box called #MyFormFieldName with this to allow a user to enter details. @using System.Net.Mail; **This method is not necessarily best practice, we should discuss other options for posting emails.**
@using Contensis.Framework.Web;
@using System.Net.Mail;
@if (IsPost) {
string EmailFrom = "[email protected]";
string EmailTo = "[email protected]";
MailMessage email = new MailMessage();
email.IsBodyHtml = true;
string emailBody = "";
@ps-team
ps-team / Breadcrumb.cshtml
Created October 27, 2017 09:52
Contensis Razor Breadcrumb - webAPI only
@using Contensis.Framework.Web;
<ul>
<li>
You are here:
</li>
@breadcrumb(CurrentNode)
@helper breadcrumb(Node node)
{
@ps-team
ps-team / breadcrumbs-combined.cshtml
Created October 27, 2017 09:56
Razor breadcrumbs that work with both legacy content pages AND entries - requires customUtilities.cshtml (another gist)
@using Contensis.Framework.Web;
@using System.Web;
@{
// check if this is an entry
var entryUrl = "";
var entryTitle = "";
if (HttpContext.Current.Items["entryUrl"] != null)
{
entryUrl = HttpContext.Current.Items["entryUrl"].ToString();
@ps-team
ps-team / CustomUtilities.cs
Last active October 27, 2017 09:57
A set of custom utility functions for use in App_code
using System;
using System.Web;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Contensis.Framework.Web;
using Zengenti.Contensis.Delivery;
using Zengenti.Contensis;
using Zengenti.Populo;
@ps-team
ps-team / Hiding placeholders.vbs
Created October 27, 2017 09:58
Hiding placeholders - simple stuff, but there are bits here that can be quite useful
// Hide a placeholder if it is empty
If Control.controls.count = 0 then
If value.trim.toLower.indexof("[add content here]") > -1 Or StripHTML(HttpUtility.HTMLDecode(value).trim).length = 0 then
Control.visible = false
End If
End If
// Hide a placeholder if it is empty, also adding in a check for images.
@ps-team
ps-team / Get Author Name Email etc.vbs
Created October 27, 2017 09:59
Get Author Name Email etc
Dim authorId As String = item.Data("AuthorId")
Dim user As New CMS_API.Security.User(authorId)
Dim authorName As String = user.FirstName
@ps-team
ps-team / TopMenu.cs
Created October 27, 2017 10:00
A top menu navigation razor that allows user to set which page they want to appear using a meta data tag. Also show the next level down.
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
@{
FolderNode topFolder = null;
//Always get the current top folder regardless of depth of the current page
if(CurrentNode.Parent.Depth > 1) {
topFolder = CurrentNode.Parent.AncestorAtDepth(1);
}else{