File URL field
ThesfFileUrlField
is a directive that enables you to choose a file with a certain extension from your SitefinityWebApp
folder and returns the file's URL. You must pass an extension and all files displayed are with this extension. The extensions you may use are CSS
, JS
, and HTML
. The sfFileUrlField
directive is defined in a module with the same name: sfFileUrlField
.
URL field atributes
The sfFileUrlField
directive exposes the following attributes:
Attribute |
Description |
sf-model
|
Accepts a scope variable that holds the selected URL of the file. |
sf-extension
|
Accepts a string as the file extension to search for. |
sf-title
|
Accepts a string as the title to show on the modal window when selecting file. |
sf-template-url
|
Allows you to override the template of the sfFileUrlField directive. |
sf-template-assembly
|
Specifies the assembly where the template of the sfFileUrlField directive is located. |
Add the URL field directive
The following example demonstrates how to add asfFileUrlField
directive in a widget designer's view.
To enable AngularJs to link the sfFileUrlField
directive in your custom designer view, you must load the script of the directive and add a dependency to the module:
- 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. As a result, the file content should be similar to the following:
-
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, right before the definition of your custom view controller, place the following code snippet:
In the code above, the URL of the selected CSS is stored in the $scope.fileUrl
variable.
-
In your
DesignerView.YourView.cshtml
file, place the following tag where you want to render the sfFileUrlField
directive: