Aspect ratio selection directive

The aspect ratio selection enables you to display and retrieve selected width, height, and aspect ratio.

The settings you select are kept in an object variable that has widthheight, and aspectRatio properties. The default template renders four options for aspect ratio - Auto, 4x3, 16x9, Custom. When Auto is selected, you can not edit width and height. When 4x3 or 16x9 aspect ratio option is selected, when you edit the width or height, the other field will also change to fit in the selected aspect ratio.

You can use the aspect ratio selection in the frontend, as well as in the backend. For example, on a page, as well as in a widget designer.

The sfAspectRatioSelection is a directive with an isolated scope that is defined in a module with the same name: sfAspectRatioSelection.
For more information, see Isolating the Scope of a Directive


The sfAspectRatioSelection directive exposes the following attributes:

Attribute Description
Accepts a scope variable that holds the selected width, height and aspect ratio.
Allows you to override the template of the aspect ratio selection.
Specifies the assembly where the template of the aspect ratio selection is located.

Add the aspect ratio selection directive

The following example demonstrates how to add a aspect ratio selection directive in a widget designer's view.

To enable AngularJS to link the sfAspectRatioSelection directive in your custom designer view, you must load the script of the directive and add a dependency to the module.
Perform the following:

  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.
    Use the following code:
  2. In your designerview-yourview.js file, place the following code snippet:

    The code above shows an aspect ratio selection that enables you to select and edit aspect ratio, width and height. The selected values are kept in the aspectRatioModel object.

  3. In your DesignerView.YourView.cshtml file, place the following tag where you want to render the sfAspectRatioSelection directive:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

DateTime picker