A Guide to CMS Functions

Types of Functions

When creating functions, developers and designers are not limited to one technology in C1 CMS and have a choice of several types:

To the end user such as a content author, the functions look and behave uniformly in most cases. It means that when the content editor adds a function on a page, he or she does not really know what type of function it actually is.

Figure 3: Six types of function

Out of these 6, Razor, XSLT and C# functions are most commonly used in C1 CMS. (This statistics might help you prioritize topics to further study if you are going to learn more about CMS functions.)

In the following few sections, most function types will be discussed in detail.

Visual Functions

Visual functions are the simplest and most user-friendly way of rendering dynamic content in C1 CMS. That, of course, comes with a price. Being the simplest means being less flexible if compared to other types. However, if you are just starting with functions as well as data types, Visual functions might be quite helpful.

Figure 4: A Visual function

As dynamic content is based on use of data types in C1 CMS, the Visual functions are a quick and convenient way of presenting data these data types contain.

One visual function always stands for one data type. You cannot use a visual function to present data from two or more datatypes.

Visual functions present data as a list of data items. Each data item displays values in the data type fields.

Figure 5: Content rendered by a visual function

The creator of a visual function can select which fields to use for rendering as well as sort items by one field and limit the number of items to display.

For more information, please see the “Guide to Visual Functions”.

Parameters of Visual Functions

You do not define parameters for Visual functions. All visual functions come with the same set of input parameters (function properties when inserted on a page):

  • List Filter: The filter applied to the data to select items to show. No filtering by default. (Available in the Advanced view only.)
  • Item list length: The maximum number of items to show. The default value is 10.
  • Item sorting: The field to use when sorting items. The default value is the field in the data type set as a title. You can also use '(random)' to show items randomly.
  • Sort ascending: When checked (“True”), items are sorted in ascending order (alphabetically or chronologically). The default value is “True”. This field is ignored when '(random)' sorting is active.

Figure 6: Parameters of a visual function (when inserted on a page)

All these parameters come with default values. However, you can override them by switching to the Advanced view and specifying constant values for, or executing function calls on, them.

Figure 7: Parameters of a visual function in the Advanced view (when inserted on a page)

(For information on parameters in CMS functions, please refer to How to Set Function Parameters further in this guide.)

XSLT Functions

XSLT functions are key functions in C1 CMS. As XSLT is all about transforming XML, XSLT functions transform anything that can be passed to it in XML format. In terms of C1 CMS, “anything” means “everything”. All the power of XSLT is available in XSLT functions.

Figure 8: An XSLT function

XSLT functions have all the uses outlined in the section Purposes of Using Functions.

XSLT functions can be used to insert portions of shared content in multiple destinations, for example, templates or pages. Unlike Visual functions, XSLT functions can present data from data types in a flexible and highly customizable way, not only as one-to-one field-by-field representation but also as a result of processing and transforming values in those fields and more.

Internally, a XSLT function can use outputs of other CMS functions available in the system.

For more information, please see the “Guide to XSLT Functions”.

Parameters of XSLT Functions

An XSLT function allows its end users to customize the appearance and behavior of its output by setting its input parameters. Each XSLT function might have no, one or more parameters that differ from function to function.

(For information on parameters in CMS functions, please refer to How to Set Function Parameters further in this guide.)

Razor Functions

Razor Functions allow you to create CMS functions using the Razor syntax. Basically, you can mix in and use C# code within your XHTML.

Figure 9: A Razor function

Razor Functions can make a good alternative to using either XSLT or C# functions or even both.

For more information, please see the “Guide to RazorFunctions”.

Parameters of Razor Functions

Defining parameters are different from defining them in XSLT functions.

Any public property declared within @function directive serves as a Razor Function’s parameter. And you can fine-tune these parameters with the FunctionParameter attribute.

For more information, please see “Defining Razor Function Parameters”.

User Control Functions

User Control Functions allow you to turn standard ASP.NET User Controls into regular CMS functions.

Figure 10: A User Control function

These functions are a quick and easy way of embedding your custom controls within pages, page templates and other CMS functions.

For more information, please see the “Guide to User Control Functions”.

Parameters of User Control Functions

Defining parameters are different from defining them in XSLT functions but similar to that in Razor functions.

Any public property declared within the control class will make a User Control Function’s parameter. And you can extend these parameters with the FunctionParameter attribute.

For more information, please see “Defining User Control Function Parameters”.

C# Functions

In C1 CMS, you can use external C# code, which, when being exposed in a specific manner, can be made available in C1 CMS as a C# function.

Figure 11: A C# function

With all the power of .NET Framework and C# on the one hand and programmatic access to a C1 CMS website and all its constituents via C1 CMS APIs on the other hand, C# functions proves to be highly effective tools in web development and web design in C1 CMS.

To the end user, they look nothing more than regular “CMS functions” and can be used in the same manner as other types.

Unlike Visual and XSLT functions, C# functions are more developer-oriented. You will more than often come across C# functions in function calls from within XSLT functions than in the source code of C1 CMS web page. They might be used internally in XSLT functions to perform tasks that XSLT code cannot perform.

Like XSLT functions, they can serve multiple purposes or combination thereof. They can help reuse shared content, render dynamic content or integrate external functionality within C1 CMS.

For more information, please see the “Guide to C# Functions”.

Parameters of C# Functions

A C# function in C1 CMS represents an “actual” exposed method in a specific class (type) in C# code added to the website. Therefore, all the method’s parameters are available as parameters of such a CMS function.

Users of C# functions work with its parameters as with those of other types of functions.

(For information on parameters in CMS functions, please refer to How to Set Function Parameters further in this guide.)

SQL Functions

SQL functions in C1 CMS allow you to make queries in databases using SQL syntax.

Figure 12: An SQL function

As some queries (SELECT) return data, SQL functions with these queries can return data, too. The returned data is in XML format and can be further used directly in other functions being processed and rendered or even directly on a page.

The functions can be used on any databases that support SQL queries.

You can also use SQL functions to execute stored procedures in databases.

For more information, please see the “Guide to SQL Functions”.

Parameters of SQL Functions

An SQL function allows its users to customize its logic by setting its input parameters. Each SQL function might have no, one or more parameters that differ from function to function. The input parameters are further used in its SQL query as regular SQL variable.

Users of SQL functions work with its parameters as with those of other types of functions.

(For information on parameters in CMS functions, please refer to How to Set Function Parameters further in this guide.)

MVC functions

MVC functions are the way of integrating ASP.NET MVC applications into C1 CMS. You can register your MVC controllers and actions as CMS functions without changing your MVC applications, or you can make small changes to the latter and have C1 CMS auto-discover them.

MVC functions are not built-in in the system as the other types of CMS functions are. The MVC functions are available in C1 CMS via a special addon. In the GUI, they are only visible in the Insert Function window and not available from the Functions perspectives.

For more information, please see the “MVC Functions”.