Defining Parameters

Define parameters in Razor functions

You can define Razor function parameters as public properties within the @function {...} directive.

Note. Most types of parameters get a corresponding default widget in the GUI. For example, if you decalre a property of the DataReference<IMediaFile> type, as a parameter it will have the MediaFileSelector widget.

To specify a parameter's label different from its name, help text, default value and/or a widget different from the default widget for this type of the parameter, you should use the FunctionParameter attribute.

The FunctionParameter attribute can have one or more of these parameters you can choose to set:

  • Label: The user-friendly name of the function parameter.
  • Help: The description of the parameter.
  • DefaultValue: The default value for the parameter if any.
  • WidgetMarkup: The widget markup for the parameter if you want to use a widget other than default for the parameter. (Read more on changing widgets.)
@functions {
	public string Title { get; set; }

	[FunctionParameter(Label = "Short Description", 
					   Help = "A short description ...",
					   DefaultValue = "(write your description here)",
					   WidgetMarkup = "<f:widgetfunction name='Composite.Widgets.String.TextArea' xmlns:f='http://www.composite.net/ns/function/1.0'><f:param name='SpellCheck' value='true' /></f:widgetfunction>")]
	public string Description { get; set; }
}

In the above sample:

  • the first parameter of the string type has the same label as its name ("Title"). It has no help text and no default value. Its widget is default (TextBox)
  • the second parameter of the string type has a label different from its name ("Short Description" vs. "Description") and has its help text set. It also has the default value specified, and its default TextBox widget is changed to TextArea.