HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In

Widget attributes

This topic describes the process for adding Widgets and configuring attributes.

B2B Commerce has a robust Content Management System that allows content editors and administrators the flexibility and control to easily design the look and feel of their website. Widgets are pre-configured content holders that allow you to rapidly add content to your pages without having to develop these elements. Widgets have a user interface that allow you to configure them to meet your needs.

The following steps show the general way to add a Widget to a site:

  1. Click the Content Add button, which opens the Add Widget menu.
432432
  1. Choose the widget from the item Type, and select the template associated with the widget.
  2. Each widget has a CSS class assigned to it. You can change the CSS class on any widget.
481481

Widget class definitions must inherit from AbstractWidget. Customize the display name by decorating the class with the DisplayName attribute. If a DisplayName attribute is not used, the class name, by spacing camel casing, will be used by default. So "ContactUsForm" would default to "Contact Us Form". This class then becomes the Model in the MVC view.

[DisplayName("Form - Contact Us")]
        public class ContactUsForm : AbstractWidget

Use any one of the following attributes to decorate properties with pre-defined functionality. These properties will then generate the appropriate input fields when editing pages or widgets in the CMS.

AttributeDescription
AllowedChildrenLimit an AbstractPage so that it can only have children of a type specified
AllowedParentsList of pages that the widget is allowed to be added to
CheckBoxContentFieldUses "CheckBox" template
DatePickerContentFieldUses "DatePicker" template, includes a property to set whether to include time on the date.
DropDownContentFieldUses "DropDown" template, contains a property for setting of values in the dropdown list
EnumDropDownContentFieldInherits from DropDownContentFieldAttribute, adds an Enum type as a list of values for a dropdown list
FilePickerContentFieldUses the "FilePicker" template.  Allows setting of the ResourceType for the FilePicker, sets a default value of "UserFiles"
IntegerContentFieldInherits from TextContentFieldAttribute and sets the RegExValidation to enforce an integer value.  Currently being used on the NewsList page for setting a default page size
ListContentFieldUses the "List" template. Allows adding content that contains a list of items, such as: on the Contact Form Edit Content screen you can "Add" multiple email addresses and "Available Topics"
ListOfPagesContentFieldUses the "ListOfPages" template.  Currently used on a LinkList widget that displays a list of links to pages based on the pages found that are related to the "keys" found in the ListOfPages property
RichTextContentFieldUses "RichText" template
SelectContentItemTypeUsed inside a TemplatePage and used on the PageType property to set the type to a "ContentPage"
SelectedPageContentFieldUses on the ItemList (RootPageName property), ItemLink (LinkedContentName property) and NavigationList (RootPageName property) widgets.  Sets the Template to the "SelectedPage" template
TextAreaContentItemFieldUses the "TextArea" template.
TextContentFieldUses the "Text" template.  Allows you to set a RegEx validation on the text template

These attributes are built into the B2B Commerce framework located in the InSite.Content.Attributes namespace. Additional attributes can be built and extended to provide custom functionality within B2B Commerce.

For example the RichTextContentField provides a textbox with WYSIWIG functionality.

[RichTextContentField(IsRequired = true)]
  public virtual string SuccessMessage
  {
    get { return GetValue("SuccessMessage", "Your message has been sent.", FieldType.Variant); }
    set { SetValue("SuccessMessage", value, FieldType.Contextual); }
  }

The getters and setters for properties need to also make use of the methods GetValue and SetValue to properly persist data. FieldType.Contextual means the property value can vary by Context (Language, Persona, DeviceType). For fields that don't need to vary by context, FieldType.General can be used.

For example, Title needs to have a different value based on the current language.

It is possible to limit widgets by parent type. For example, the ZoneWidget can only be added to a TemplatePage.

For a given widget, such as RichContent, there can be one or more templates defined. If there is a need to create new functionality to display RichContent, an additional View could be added to the path of the RichContent folder.


What’s Next