Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / ImageAltText.cs
Created October 27, 2017 09:35
How to get the alt text of an Image node using the WebApi
@using Contensis.Framework.Web
@{
NodeFactory nf = new NodeFactory();
ContentNode n = (ContentNode)nf.LoadById(####);
<img src="@n.Path" alt="@n.MenuName" />
}
@ps-team
ps-team / List all sibling pages excluding folder homepage.cshtml
Created October 27, 2017 09:35
Simple Razorview to list all sibling pages in a folder and exclude the folder homepage using meta data to generate the link title.
@using System.Collections.ObjectModel
@using Contensis.Framework.Web
@{
// links in containing folder
ReadOnlyCollection<ContentNode> nodes = CurrentNode.Siblings(false);
// render - links if they exist
if(nodes.Count > 0)
@ps-team
ps-team / CanonicalTagging.cshtml
Created October 27, 2017 09:35
Canonical tags in Razor. I made some changes to point URL's with query strings back at the URL without the QS as this was showing up as duplicated content in GA.
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
@using System.Collections
@using System.Collections.ObjectModel
@using System.Text.RegularExpressions;
@{
if (CurrentNode.Data.Property_SynchronisationSourceMasterContentID >= 0)
{
int masterPageContentID = CurrentNode.Data.Property_SynchronisationSourceMasterContentID;
Node masterPage = null;
@ps-team
ps-team / Email validation.cshtml
Created October 27, 2017 09:34
A re-usable C# function for backend email validation. No need to use long REGEX which, depending on the expression, may not capture all possibilities. The .Net MailAddress class does all this for us, so by sending it a string with an invalid email format, it will error which we can capture and use to dictate what to do next.
@using System.Net.Mail
@{
string email = "[email protected]";
if(IsValidEmail(email))
{
// do something like submit the form and store the data, send an email or w/e
}
else
@ps-team
ps-team / BasicNodeQuery.cs
Created October 27, 2017 09:33
Example of doing a basic Node Query and how to render the data it returns
<control name="News Listing Using Node Query" showInMenu="true" category="Dev Training" viewingGroup="1">
<properties>
<nodeQuery name="NewsArticlesQuery" orderby="Property_DatePublished desc">
<where property="Type" operator="IsEqualTo" value="News" />
</nodeQuery>
</properties>
</control>
@using Contensis.Framework.Web;
@using System.Collections.ObjectModel;
@ps-team
ps-team / NodeQuery-SearchParameteres.xml
Created October 27, 2017 09:33
These example show passing search parameters either form the query string or a from posted data to a node query
<control name="News Listing Using Node Query" showInMenu="true" category="Dev Training" viewingGroup="1">
<properties>
<nodeQuery name="NewsArticlesQuery" orderby="Property_DatePublished desc">
<where property="Type" operator="IsEqualTo" value="News" />
<and property="Title" operator="Contains" value="@Request.Querystring.Keywords" />
<and property="Data.TaxonomyCategories" operator="Contains" value="@Request.Querystring.category" />
</nodeQuery>
</properties>
</control>