Documentation > CMS Template API Library > Util

CrownPeak.CMSAPI.Util

Contains a set of utility methods.

NameDescriptionType
ConvertTextToHtml

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

Method
CreateListFromCsv

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

Method
Crop

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

Decodes HTML encoded entities only and changes them to characters.

Method
DeleteHttp

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

Method
DeserializeDataContractJson

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

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

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

Method
Editable

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

Used to send an email from the cms.

Method
Email

Used to send an email from the cms.

Method
EscapeItem

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

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

Method
FilterText

Filters the text based on the .

Method
GetExtension

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

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

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

HTML Encodes the text.

Method
LoadXml

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

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

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

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

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

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

Method
MinifyCSS

Minifier for CSS

Method
MinifyJS

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

Method
MinifyJS

Minifier for JavaScript

Method
Paginate

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

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

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

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

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

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

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

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

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

Method
PostToTwitter

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

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

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

Finds cpt_internal style links in your HTML and replaces them with links appropriate for the current context.

Method
SerializeDataContractJson

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

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

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

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

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
ShortenWithBitly

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
ShowEditButton

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

Method
StartCase

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

Removes html tags from the given text.

Method
UrlEncode

Used to encode characters that are not legal in URLs.

Method
WrapText

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