Site selector

The following tutorial demonstrates how to add a Site selector in your widget's designer. You use the Site selector to select different sites defined in your Sitefinity CMS application.

Add Site selectors

  1. Sitefinity CMS automatically registers the scripts you need and, if no other designer view with explicitly set priority exists, Sitefinity CMS sets your designer view priority 1. In case you need to have full control over the scripts that are loaded or you want to set custom priority, you can alternatively create your own DesignerView.YourView.json file. If you have a JSON file that matches the convention (even if empty), this automatic scripts registration will not occur. In your DesignerView.<YourView>.json file, add a scripts array. The content of the file should be similar to the following:

    For more information on the scripts that you must load, see List of selectors scripts reference.

  2. Sitefinity CMS automatically finds all AngularJS modules you rely on and references the widget designer to them. In case you rely on custom AngularJS modules or have logic that needs an AngularJS controller, you can create your own designerview-<yourview>.js file. If you have a .js file that matches the convention (even if empty), this automatic modules referencing will not occur. In your designerview-<yourview>.js file, place the following code in your designer's controller:

    In the code above, you use the propertyService to load the properties of your widget. Next, you create a scope property to hold the Site value. You can watch for any changes in the scope to update the widget properties. For more information about getting and setting the selected item, see Use content items selectors.

  3. In your DesignerView.<YourView>.cshtml file, place the following tag where you want to render the Site selector:

    NOTE: If you do not supply a value for the sfSite attribute, the Site selector selects the default Sitefinity CMS backend site. In addition, if Sitefinity is in single site mode the Site selector is not rendered.

Get or set the selected site

To access the selected site, you use the sf-site attribute. You must add the following property in your widget's controller:

The value of the sf-site attribute is the sfSite scope property, which has the following JSON structure:

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?

Next article

Language selector