IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
The library selector enables you to display a list of all existing libraries in your website. You can use the selector in the frontend or backend of your site. For example, you can use the selector on a page or in a widget designer. For more information about libraries, see Overview: Libraries.
For information about how to use a selector on frontend pages, see Feather: Use content selectors outside of widget designer views.
The following image is an example of a library selector:
The Library selector exposes the following attributes:
sf-media-type
sf-selected-item
sf-selected-items
sf-selected-item-id
sf-selected-ids
sf-provider
In this example, you add a Library selector in a widget designer's view. To add the Library selector:
Feather automatically registers the scripts you need and, if no other designer view with explicitly set priority exists, Feather 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 the DesignerView.<YourView>.json file, add a scripts array. As a result, the file content should look similar to the following:
DesignerView.YourView.json
JSON
DesignerView.<YourView>.json
scripts
{
"priority"
: 1,
"components"
: [
"sf-library-selector"
]
}
NOTE: For more information about the scripts that you must load, see Feather: List of selectors scripts reference.
Feather 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 the designerview-<yourview>.js file, right before the definition of your custom view controller, place the following code snippet:
designerview-<yourview>.js
.js
var
designerModule = angular.module(
'designer'
);
angular.module(
).requires.push(
'sfSelectors'
In the DesignerView.<YourView>.cshtml file, place the following tag where you want to render the Library selector:
DesignerView.<YourView>.cshtml
<
sf-list-selector
sf-library-selector
=
"images"
"selectedLibraryId"
"selectedLibrary"
"provider"
/>
The values of the attributes are scope properties that you must add in your widget's controller:
public string SelectedLibraryId
get;
set;
public string SelectedLibrary
Add the following code in your designer's controller:
designerModule.controller('YourViewCtrl', ['$scope', 'propertyService', function ($scope, propertyService) {
propertyService.get()
.then(function (data) {
if (data) {
$scope.properties = propertyService.toAssociativeArray(data.Items);
$scope.selectedLibraryId = $.parseJSON($scope.properties.SelectedLibraryId.PropertyValue);
$scope.selectedLibrary = $.parseJSON($scope.properties.SelectedLibrary.PropertyValue);
},
function (data) {
$scope.feedback.showError = true;
if (data)
$scope.feedback.errorMessage = data.Detail;
})
.finally(function () {
$scope.feedback.showLoadingIndicator = false;
});
$scope.$watch('selectedLibraryId', function (newValue, oldValue) {
if (newValue) {
$scope.properties.SelectedLibraryId.PropertyValue = JSON.stringify(newValue);
$scope.$watch('selectedLibrary', function (newValue, oldValue) {
$scope.properties.SelectedLibrary.PropertyValue = JSON.stringify(newValue);
}]);
In the code above, you use the propertyService to load the properties from the widget. Next, you create a scope property to hold the value of the selectedLibraryId and selectedLibrary. Finally, you subscribe for any changes in the scope.
propertyService
selectedLibraryId
selectedLibrary
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important