Changing Widgets
Change widgets for parameters in Razor Functions
Normally, a parameter gets its default widget, e.g. a parameter of the String type, will get a TextBox widget in the GUI.
If you want to change the parameter's widget, use the 'WidgetMarkup
' as a parameter in the FunctionParameter
attribute on the Razor function's parameter and set it to the widget markup.
You can provide the widget markup via the <f:widgetfunction> element specifying its name and its namespace. If the widget have parameters, you can specify the parameters, too, via the <f:param>
element. To get the correct widget markup:
- Log in to the CMS Console.
- In the Functions perspective, expand All Widget Functions, Widgets, and then the namespace of the widget you need (e.g.
Composite.Widgets.String
). - Select the widget function (e.g.
Composite.Widgets.String.TextArea
) and click Information on the toolbar. - Copy the widget function markup from the information view.
- Paste it as a value to the
WidgetMarkup
parameter, replacing double quotes ("...") with single quotes ('...') in the value.
Normally, you will want to change the widget if you need to use:
- a non-default widget (e.g.
TextBox
toTextArea
)@functions { [FunctionParameter("Description" , "A short description of the product", WidgetMarkup = "<f:widgetfunction name='Composite.Widgets.String.TextArea' xmlns:f='http://www.composite.net/ns/function/1.0'></f:widgetfunction>")] public string Description { get; set; } }
- a default widget with parameters set to non-default values (e.g.
SpellCheck
: 'True'
to'False
')@functions { [FunctionParameter("URL" , "The website's URL", WidgetMarkup = "<f:widgetfunction name='Composite.Widgets.String.TextBox' xmlns:f='http://www.composite.net/ns/function/1.0'><f:param name='SpellCheck' value='False' /></f:widgetfunction>")] public string Url { get; set; } }