Skip to content

Instantly share code, notes, and snippets.

@ps-team
ps-team / app_code - re-usable html helpers for razorivews1.cs
Created October 27, 2017 09:36
An example of how the app_code folder can be used to create and home re-usable html helpers that razorviews can use. These would be .cshtml files.
@*
* FILE : /App_Code/HtmlHelpers.cshtml
*@
@using System.Collections.Specialized
@helper RenderPagination(int pageNumber, int pageCount)
{
@*
* HELPER : RENDER PAGINATION
@ps-team
ps-team / app_code - re-usable functions for razorviews (1)
Created October 27, 2017 09:36
A very basic example of how the app_code folder can be used to create and home re-usable functions that razorviews can then use. These can use either be .cs or .cshtml files.
@*
* FILE : /App_Code/StringFunctions.cshtml
*@
@functions
{
@*
* FUNCTION : ENCODE STRING
* ************************
* Description : takes an input string and returns it lower-cases and url-encoded
@ps-team
ps-team / htmlheader.vbs
Created October 27, 2017 09:37
Custom Code for Adding Stuff to the header
htmlheader.text += "<link rel=""apple-touch-icon"" href=""img/apple-touch-icon.png"" />"
htmlheader.text += "<link rel=""apple-touch-icon-precomposed"" href=""img/apple-touch-icon.png"" />"
htmlheader.text += "<link href=""http://fonts.googleapis.com/css?family=Ubuntu:400,500,700,400italic,700italic|Roboto+Slab:400,700"" rel=""stylesheet"" type=""text/css"" />"
htmlheader.text += "<link href=""http://fonts.googleapis.com/css?family=Zeyada"" rel=""stylesheet"" type=""text/css"" />"
@ps-team
ps-team / Get a property or metadata from a page, in a safe way.vbs
Created October 27, 2017 09:38
Get a property or metadata from a page, in a safe way (so if the metadata doesn't exist it doesn't fall over). In this example we're replacing the title of a page based on metadata
if variable("MD_AlternativeTitle") isnot nothing then
Me.TitleBar = variable("MD_AlternativeTitle")
end if
@ps-team
ps-team / GetDaySuffix.cs
Created October 27, 2017 09:38
Gets suffix for current day (st, nd, rd or th)
@{
int lastUpdatedOnDay = CurrentNode.Data.DateModified.Day;
string lastUpdatedOn = lastUpdatedOnDay + GetDaySuffix(lastUpdatedOnDay) + CurrentNode.Data.DateModified.ToString(" MMMM yyyy");
}
<span>Last updated on @lastUpdatedOn</span>
@functions {
//Gets suffix for current day (st, nd, rd or th)
string GetDaySuffix(int day)
@ps-team
ps-team / Localisation part 1 - get all nodes in current language.cshtml
Created October 27, 2017 09:40
Localisation - using localisation in Contensis razorviews - In razor we can access the current pages' language folder and then use that to look-up all nodes in the CMS that are in that language. So for example, we can use this to build a custom search results razorview, which is language specific. Or we can build up a more specific search query …
@using System.Collections.ObjectModel
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
@{
@*
- assuming the site structure has been setup so that all content for each language
- is contained in a language folder that sits under the website root, we target the
- current pages' language folder and create a dynamic path variable which we tie into
@ps-team
ps-team / RemoveShippedjQueryVersion.vbs
Created October 27, 2017 09:42
Oh, man. This is horrible. But sometimes needed in older versions where you can't remove jQuery due to a control rendering it out. Honestly, don't use this.
'Jquery reference code
Dim js = From file In Javascript.Files
Where file.Key = "jquery"
if js.count > 0 then
Javascript.Files.Remove(js.First())
end if
Javascript.Files.Insert(0, New CMS_API.Utilities.Javascript.UrlJavascriptFileReference("/SiteElements/Scripts/jquery.js"))
@ps-team
ps-team / Validating Meta Data variable assignments.cshtml
Created October 27, 2017 09:48
Smarter variable assignment of Meta Data to prevent Razorviews from potentially falling over
@using Contensis.Framework.Web
@{
@*
- Sometimes meta data does not always become instantly available when building/previewing templates/pages,
- or if the preview database is cleared and is in the process of rebuilding itself.
-
- Depending on how you access the meta data, this can cause a razorview to fall over:
- ERROR: 'Cannot perform runtime binding on a null reference'
@ps-team
ps-team / TemplateLookup.cshtml
Created October 27, 2017 09:49
A 'maintenance' razorview - displays an alphabetical list of all used template types in a site with a page count for each template
@using Contensis.Framework.Web
@{
@*
- this is more of a 'maintenance' razorview
- displays an alphabetical list of all used template types in a site with a page count for each template
*@
<h2>List of all used templates with page count</h2>
@ps-team
ps-team / GetPLaceholderDataInRazor.cshtml
Created October 27, 2017 09:49
jMoo's amazing placeholder data in razor magic unicorn wizardry - Example of getting placeholder data in razor
@using System.Data;
@using Contensis.Framework.Web;
@using Contensis.Framework.Web.Search;
@using Contensis.Core.Utilities.DataAccess;
@{
var relatedContent = CurrentNode.RelatedNodes();
var dal = new SqlDataAccess(Contensis.Framework.Web.AppContext.Current.Server.ConnectionString);
}