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 following tutorial demonstrates how to add a Link selector in your widget's designer. The Link selector generates hyperlinks to a website, a page from this site, a specific anchor in the text, or an e-mail address. For more information on how to use the Link selector, see Feather: Use Link selectors in Content block widgets.
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 your DesignerView.<YourView>.json file, add ascripts array. The content of the file should be similar to the following:
DesignerView.YourView.json
JSON
DesignerView.<YourView>.json
scripts
{ "priority": 1, "components" : ["sf-link-selector" ] }
For more information on 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 your designerview-<yourview>.js file, place the following snippet right before the definition of your custom view controller:
designerview-<yourview>.js
.js
var
designerModule = angular.module(
'designer'
);
angular.module(
).requires.push(
'sfSelectors'
In your DesignerView.<YourView>.cshtml file, place the following tag where you want to render the Link selector:
DesignerView.<YourView>.cshtml
<sf-link-selector sf-link-html="link" sf-selected-item="selectedItem" sf-editor-content="editorContent"></sf-link-selector>
NOTE: If you use the Link selector in a text editor, you can select a word or a phrase to convert into a hyperlink. The selected word or hyperlink must be passed to the sf-link-html attribute. You can use the sf-selected-item attribute to access the link item generated from the value of sf-link-html.
sf-link-html
sf-selected-item
sf-link-htm
To access the selected value, you use the sf-link-html attribute. You must add a property in your widget controller that stores the generated hyperlink:
public string Link
{
get;
set;
}
Add the following code in your designer's controller:
designerModule.controller('YourViewCtrl', ['$scope', 'propertyService', 'sfLinkService', function ($scope, propertyService, linkService) {
$scope.feedback.showLoadingIndicator = true;
//Makes call to the controlPropertyService to get the properties for the widgets.
propertyService.get()
.then(function (data) {
if (data) {
$scope.properties = propertyService.toAssociativeArray(data.Items);
$scope.link = jQuery($scope.properties.Link.PropertyValue);
},
function (data) {
$scope.feedback.showError = true;
if (data)
$scope.feedback.errorMessage = data.Detail;
})
.then(function () {
$scope.feedback.savingHandlers.push(function () {
var htmlLinkObj = linkService.getHtmlLink($scope.selectedItem);
$scope.properties.Link.PropertyValue = htmlLinkObj[0].outerHTML;
});
.finally(function () {
$scope.feedback.showLoadingIndicator = false;
}]);
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 Link property. In the widget designer, you can select what type of hyperlink to create. When you click Save, the getHtmlLink function of the sfLinkService is called and you pass the value of the sf-selected-item attribute. The getHtmlLink function returns a hyperlink and you can save its outerHTML in the Link property.
propertyService
Link
getHtmlLink
sfLinkService
outerHTML
The Link selector has an option to set a hyperlink to an anchor. To do this, you use the sf-editor-content attribute. The attribute value must contain text from which anchors can be extracted. For example, you can set the editorContent property in the scope of your designer's controller to have the following value:
sf-editor-content
editorContent
$scope.editorContent = "<
h2
id
=
'myTitle'
>Hello World</
div
> Some text <
span
'mySpan'
>some span text</
>";
As a result, the anchors myTitle and mySpan appear in the Anchors dropdown box on the Anchor tab.
myTitle
mySpan
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