Skip to content

Instantly share code, notes, and snippets.

@ps-team
Created October 27, 2017 14:16
Show Gist options
  • Save ps-team/8558dc6f6099e7be59160a7e373f9c61 to your computer and use it in GitHub Desktop.
Save ps-team/8558dc6f6099e7be59160a7e373f9c61 to your computer and use it in GitHub Desktop.
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)
////////////////////////////////////////////////////////
'add a script at the end of the body tag
CurrentContext.Page.Scripts.Add("/NewGenerationSite/j/eventsjs.js", ScriptLocation.BodyEnd);
// code for collapsing a placeholder based on whether there are subtemplates or text inside it.
if Control.controls.count = 0 andalso (value = "" OrElse value= "[add mini-templates here]") then
sideColumn.visible = false
mainColumn.attributes("class")= mainColumn.attributes("class") & " sys_col1-expanded"
response.write("hide")
else
response.write("has controls")
end if
exit sub
///### THis first one works ###///
If Control.controls.count = 0 then
If value.trim.toLower.indexof("[add … here]") > -1 Or StripHTML(HttpUtility.HTMLDecode(value).trim).length = 0 Or StripHTML(value).trim() = " " then
Control.Parent.visible = false
End If
End If
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
If Control.controls.count = 0 then
If value.indexof("<img") = -1 then
If StripHTML(HttpUtility.HTMLDecode(value).trim).length = 0 then
Control.visible = false
Else
If value.trim.toLower.indexof("insert a link") > -1 then
Control.visible = false
End If
End If
End If
End If
------------------------------------------------------------------------------------------------
// code for hiding divs (set div to runat="server" first!)
{name of div ID here}.visible = false
------------------------------------------------------------------------------------------------
//Code for adding Javascript files
//Jquery
Utilities.RegisterJquery
//jQuery R8
AppContext.Current.Page.Scripts.RegisterJQuery()
//r6
Utilities.RegisterJavaScriptFile("/SiteElements/Scripts/tabbox.js")
//R7.2
CurrentContext.Page.Scripts.Add("/SiteElements/Scripts/checkbox.js")
//Add javascript just before the closing body tag
Javascript.StartUpJavascriptFiles.Add("/SiteElements/Scripts/flexslider.js")
//Code for adding stylesheets in custom code
CurrentContext.Page.CSS.Add("/SiteElements/Stylesheets/550-structuredContent.css")
------------------------------------------------------------------------------------------------
// If statement based on current page id
if me.ContentId {= < > etc} 1 then
[do something]
end if
//for example;
if me.ContentId <> 1 then
TitleBar.text = TitleBar.text & " -Page Title"
end if
** "else" and "elseif" can also be used. Not is done by using "if not"
------------------------------------------------------------------------------------------------
'Add conditional CSS files to head
ContensisHeader.Text += "<!--[if lte IE 7]>" & Environment.Newline
ContensisHeader.Text += "<link rel=""stylesheet"" type=""text/css"" href=""/SiteElements/Styles/901-ie7.css"" />" & Environment.Newline
ContensisHeader.Text += "<![endif]-->" & Environment.Newline
ContensisHeader.Text += "<!--[if lte IE 9]>" & Environment.Newline
ContensisHeader.Text += "<script type=""text/javascript"" src=""SiteElements/Javascript/compat.js""></script>" & Environment.Newline
ContensisHeader.Text += "<![endif]-->" & Environment.Newline
// Text in footer?
FooterLit.Text = "<scr" & "ipt type=""text/javascript"" src=""/SiteElements/Javascripts/fixpng.js""></scr" & "ipt><noscript>Warning: png images may not display correctly as your browser does not support JavaScript.</noscript>"
-------------------------------------------------------------------------------------------------
'Add responsive meta tag thingy
ContensisHeader.Text += "<meta name=""viewport"" content=""width=device-width, initial-scale=1"">" & Environment.Newline
-------------------------------------------------------------------------------------------------
// LANGUAGE Selection
'Customised Language Toggle Link
Dim contentId As Integer = Property_c_id
Dim url As String = ""
'Try
'If on en page
' If Property_PageLanguageId = 1 Then
' LanguageToggleHyperlink.Text = "Cymraeg"
' Dim navProvider As CMS_API.Navigation.NavigationProvider = CMS_API.Navigation.NavigationProviderFactory.GetNavigationProvider(CMS_API.Navigation.NavigationProviderType.Xml)
' Dim navContent As CMS_API.Navigation.INavigationContent = CType(navProvider.GetItemByDatabaseID(contentId, CMS_API.Navigation.NavigationItemTypes.Webpage), CMS_API.Navigation.INavigationContent)
' if navContent.SlaveNavigationContentList.count > 0 then
' url = navContent.SlaveNavigationContentList(0).Url
'response.write(url)
' LanguageToggleHyperlink.NavigateUrl = url
' end if
' Else If Property_PageLanguageId = 8 Then
' LanguageToggleHyperlink.Text = "English"
' Dim navXmlHelper As CMS_API.Utilities.NavigationXMLHelper = CMS_API.Utilities.NavigationXMLHelper.Instance
' Dim xmlId As String = navXmlHelper.GetElementXmlId(contentId, CMS_API.Utilities.NavigationXMLHelper.MenuType.pageitem)
' Dim masterContentID As Integer = navXmlHelper.GetElementMasterContentId(xmlId)
' url = System.Web.HttpUtility.HtmlEncode(CMS_API.Utilities.NavigationXMLHelper.Instance.GetPagePath(masterContentID))
' LanguageToggleHyperlink.NavigateUrl = url
'Search redirect
' SearchQueryControl.resultsurlwebpageid = 23522
' End If
'Catch Ex As Exception
'Toggle link uses default setting and goes to cy homepage
'End Try
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment