Enabling Sass in Backoffice-based Extension

The steps described in this section are to guide you through the process of enabling Sass in your Backoffice-based extension.

Prerequisites

You must state in extensioninfo.xml that Backoffice extension is the required extension or indirectly required extension.

Context

You have created and a custom Backoffice-based extension without enabling Sass in the very beginning, or you have an already existing Backoffice-based extension, which was developed before Sass support was introduced. Now, you would like to add Sass to your extension so that it can be used instead of standard CSS. Here are the steps how to enable Sass in the already existing Backoffice-based extension.

Procedure

  1. Register your extension as Sass extension.
    1. Navigate to the myextensionbackoffice/buildcallbacks.xml file and add the following callback:
      <macrodef name="myextension_before_build">
          	<sequential>
              	<register_sass_extension extensionname="myextensionbackoffice"/>
              	<register_sass_extension extensionname="myextensionbackoffice" resources="resources" destination=""/>
          	</sequential>
      	</macrodef>
    2. Specify the resources and destination parameters.
  2. Create the variables file, where you can define your custom variables.
    1. In the myextensionbackoffice/backoffice/resources/scss, create the myextensionbackoffice-variables.scss file. It can be defined as follows:
      $backgroundColor: #fa2e35;
  3. Change all your CSS files to SCSS files as per the following example:
    1. Navigate to the myextensionbackofficewidget.css and rename it to myextensionbackofficewidget.scss.
    2. In the myextensionbackoffice.scss, change the hard-coded color, so that it is defined by the variable specified in the myextensionbackoffice-variables.scss file:
      Change
      .yw-labelstyle
      {
      	color: red;
      }
      to:
      .yw-labelstyle
      {
      	color: $backgroundColor;
      }
  4. Recompile the extension by running ant clean all and restart the server.