Documentation > CMS Template API Library > Util

CrownPeak.CMSAPI.Util

Contains a set of utility methods.

NameDescriptionType
ConvertTextToHtml(String)

Replaces non standard characters to their HTML equivalent such as smart quotes.

Method
CreateListFromCsv(String,Char)

Converts CSV file contents into a List of Dictionaries. Requires the first line in the data to be column headers.

Method
Crop(String,Int32,Boolean)

Crops the specified string. If the string length is less than the crop length, the string will not be cropped. Crop tries to be smart about where it crops the string. Rather than croping a word midway through, it will crop at the right most space within the bounds set by the cropLength parameter. If a space does not exist within this section, it will crop the string at cropLength. appendEllipsis is an optional parameter that when set to true, will append an ellipsis to the end of the string. Since the ellipsis occupies 3 spaces, the cropLength will be adjusted by a factor of three. If the string is null, empty, or all whitespace, an empty string is returned.

Method
DecodeEntities(String)

Decodes HTML encoded entities only and changes them to characters.

Method
DeleteHttp(String,DeleteHttpParams)

Sends a DELETE request to the provided URL. Use the DeleteHttpParams object to set optional values for timeout and headers.

Method
DeserializeDataContractJson(String,Type)

Define a class that uses [DataContract], [DataMember], and [EnumMember] tags and you can then create an object from a json representation of the object with this method Use the Name property in the DataMember to use a name that is different from the property name -- [DataContract(Name="MySpecialName")] Use the Namespace in the DataContract to use a namespace that is custom for XML -- [DataContract(Namespace = "MySpecialNamespace")]

Method
DeserializeDataContractXml(String,Type)

Define a class that uses [DataContract], [DataMember], and [EnumMember] tags and you can then create an object from a xml representation of the object with this method Use the Name property in the DataMember to use a name that is different from the property name -- [DataContract(Name="MySpecialName")] Use the Namespace in the DataContract to use a namespace that is custom for XML -- [DataContract(Namespace = "MySpecialNamespace")]

Method
DeserializeXml(String,Type)

Define a class that uses [XmlElement], [XmlAttribute], and other tags and you can then create an object from XML with this method

Method
Editable(String,PanelEntry,Asset)

Returns HTML attributes that enable the editing selection boxes for an asset field in the CMS. For use in output templates only. The attributes should be inserted into the wrapping HTML tag. If the editable element is inside a list panel, also include the . If the editable element is inside another asset, also include the

Method
Email(String,String,List[String],String,ContentType)

Used to send an email from the cms.

Method
Email(String,String,String,String,ContentType)

Used to send an email from the cms.

Method
EscapeItem(String)

Escapes html characters and all non-ASCII UTF-8 characters. If the string already contains escaped values, such as &, it will not escape the &.

Method
FilterFilename(String)

Filters the text based upon the Filename configuration in the CMS. The filters can be set at System > Configure > Filenames

Method
FilterText(String,FilterTextType)

Filters the text based on the .

Method
GetExtension(String)

Takes a filename and returns its extension. Wil return empty if no extension is found. Ex: GetExtension("input.aspx") will return "aspx"

Method
GetHostName()

Gets Host Name

Method
GetHttp(String,GetHttpParams)

Sends a GET request to the provided URL. Can accept a set of optional GetHttpParams to override the default timeout value of 30 seconds as well as adding headers to the request.

Method
GetWorkflowTransitions(Int32)

Returns workflow transition information for the given asset. These represent state changing transitions (and refreshes). They are recorded in the audit. This method extracts workflow related transitions from the audit.

Method
HtmlEncode(String)

HTML Encodes the text.

Method
LoadXml(String,String,Dictionary[String,String])

Converts the xml into a list of XmlNodes. Passing a value for elementName will return the subset of nodes that are contained within the elementName node.

Method
Log(Asset,String,Object[])

Logs a Custom log in the context of the given asset with the given message string. The log will be added to the asset's History (Properties > History) with the action type "Custom" and will only be displayed when "Custom" is selected from the drop-down.

Method
Log(String,Object[])

Logs a Custom log in the global context with no applicable asset with the given message string The log will be added to the System History (Reports > Audit > System) with the action type "Custom"and will only be displayed when "Custom" is selected from the drop-down.

Method
MakeList(Int32[])

Convenience method for making a list of strings. You may pass an array of ints or a variable length list of ints like List list = Util.MakeList(4,8,15,16,23,42);

Method
MakeList(String[])

Convenience method for making a list of strings. You may pass an array of strings or a variable length list of strings like List list = Util.MakeList("Apple","orange", "Banana");

Method
MinifyCSS(Asset)

Minifier for CSS Uses UTF-8 to decode a binary CSS file.

Method
MinifyCSS(String)

Minifier for CSS

Method
MinifyJS(Asset)

Minifier for JavaScript Uses UTF-8 to decode a binary JS file.

Method
MinifyJS(String)

Minifier for JavaScript

Method
Paginate(Asset,String)

For use with WYSIWYG fields only. Separates the field on page breaks, and returns a portion of the field based on the current page number (context.PageNumber). This may only be used in an output template. NOTE: Page numbers are added to filenames and URLs BEFORE any filename or url templates are run. If those templates overwrite the publish path or publish URL, then the template should add the page number using the context.PageNumber property.

Method
Paginate(List[Asset],Int32)

Separates an asset list into pages, and returns a portion of the list based on the current page number (context.PageNumber) and the given itemsPerPage. This may only be used in an output template. NOTE: Page numbers are added to filenames and URLs BEFORE any filename or url templates are run. If those templates overwrite the publish path or publish URL, then the template should add the page number using the context.PageNumber property.

Method
Paginate(List[PanelEntry],Int32)

Separates a PanelEntry list into pages, and returns a portion of the list based on the current page number (context.PageNumber) and the given itemsPerPage. This may only be used in an output template. NOTE: Page numbers are added to filenames and URLs BEFORE any filename or url templates are run. If those templates overwrite the publish path or publish URL, then the template should add the page number using the context.PageNumber property.

Method
PostHttp(String,PostHttpParams)

Sends a POST request to the provided URL. Use the PostHttpParams object to set the Post Data as well as optional values for timeout, headers, and content-type.

Method
PostMessageToPingFm(String,String,String,String)

Post a message to Ping FM using CrownPeak's API key NOTE: It was announced by Seesmic in May 2012 that Ping.fm was going to be close down by Mid June 2012. This call may stop working in the near future. CrownPeak is planning to eventually support the new HootSuite APIs.

Method
PostMessageToPingFmWithCrownPeakKey(String,String,String)

Post a message to Ping FM using CrownPeak's API key NOTE: It was announced by Seesmic in May 2012 that Ping.fm was going to be close down by Mid June 2012. This call may stop working in the near future. CrownPeak is planning to eventually support the new HootSuite APIs.

Method
PostPingFmWithCrownPeakKey(Int32,String,String,String,String)

Post a message to Ping FM using CrownPeak's API key NOTE: It was announced by Seesmic in May 2012 that Ping.fm was going to be close down by Mid June 2012. This call may stop working in the near future. CrownPeak is planning to eventually support the new HootSuite APIs.

Method
PostToPingFm(Int32,String,String,String,String,String)

Post a message to Ping FM NOTE: It was announced by Seesmic in May 2012 that Ping.fm was going to be close down by Mid June 2012. This call may stop working in the near future. CrownPeak is planning to eventually support the new HootSuite APIs.

Method
PostToTwitter(Int32,String,String,String)

Post the content stored in the given asset from the field with the given name to the accoutn specified by account id.

Method
PostToTwitter(String,String)

Post the given message to the given twitter account. Be careful. This method has no built-in mechanism to prevent double-posts. Make sure it only runs once per message.

Method
PutHttp(String,PutHttpParams)

Sends a PUT request to the provided URL. Use the PostHttpParams object to set the Put Data as well as optional values for timeout, headers, and content-type.

Method
ReplaceAttachments(String)

Finds upload style links in your HTML and replaces them with links appropriate for the current context. This may only be used in an output template.

Method
ReplaceCptInternals(String,Boolean,ProtocolType)

Method
SerializeDataContractJson(Object)

Define a class that uses [DataContract], [DataMember], and [EnumMember] tags and you can then serialize an instance of that class to JSON with this method Use the Name property in the DataMember to use a name that is different from the property name -- [DataContract(Name="MySpecialName")] Use the Namespace in the DataContract to use a namespace that is custom for XML -- [DataContract(Namespace = "MySpecialNamespace")]

Method
SerializeDataContractXml(Object,Boolean)

Define a class that uses [DataContract], [DataMember], and [EnumMember] tags and you can then serialize an instance of that class to XML with this method Use the Name property in the DataMember to use a name that is different from the property name -- [DataContract(Name="MySpecialName")] Use the Namespace in the DataContract to use a namespace that is custom for XML -- [DataContract(Namespace = "MySpecialNamespace")]

Method
SerializeXml(Object)

Define a class that uses [XmlElement], [XmlAttribute], and other tags and you can then serialize an instance of that class to XML with this method

Method
SetRenderTimeout(Int32)

Modifies the default value of the Render timeout. Normally used to give long running template more time to execute, or to make sure templates don't take over x # of seconds to execute. Should be used at top of template code. Cannot be set to the maximum set by the CMS, currently 900 seconds.

Method
ShortenWithBitly(String)

Returns a shortened URL using bitly shortening service Uses first Bitly account from Connectors configuration screen that it finds. Useful if only one account is setup. Use the overload to specify a connector if there is more than one. Bitly connectors must have a username and password. The Server is optional. Leave it blank and http://api.bitly.com/v3 will be used. That is what is recommended.

Method
ShortenWithBitly(String,String)

Returns a shortened URL using bitly shortening service Bitly connectors must have a username and password. The Server is optional. Leave it blank and http://api.bitly.com/v3 will be used. That is what is recommended.

Method
ShowEditButton(Asset,String,Int32,Int32,Int32,Int32)

Displays an edit button which when clicked, will open the associated asset for editing.

Method
StartCase(String)

Converts the text to Start Case, which is the capitalization of the first letter of each word. For langauges that don't have capital letters, such as Japanese, the string will not be converted to start case.

Method
StripHtml(String,Boolean)

Removes html tags from the given text.

Method
UrlEncode(String)

Used to encode characters that are not legal in URLs.

Method
WrapText(String,Int32,String)

Wraps the text by inserting the delimiter into the text at the specified interval. WrapText will attempt to wrap the text at a word boundary in order preserve the readability of the text. As a result, some of the intervals will be less than the size provided, but never greater.

Method

Connect with CrownPeak