How to solve the issues when passing an image variable into template file from JavaScript file.

Description: According to our coding standard, we have to remove the static URL from the files where it is used. So for that, we have to pass that image into the template from the javascript file.In that time may be we are facing some issues, that issues and solutions are listed below,

  1. Points to be noticed when an image variable passes from a javascript file to a template file.
  2. The image is set into a new folder inside the Asset folder in the javascript file. The folder name like “Images”.
  3. Define the variable in the file
  4. Example
var imagearrow=Utils.getAbsoluteUrl(
                getExtensionAssetsPath(
                    "Images/right-arrow1.png"
                )
            )

5.If the image needs to be show inside an array of images on website, then we have to use _.each function

Example

 _.each(howitworks.Links, function (eachResult) {
                eachResult.arrowImg=imagearrow;
                
            });

Here, how it works is the array of objects, and use this imagearrow in template at the proper place.Then we can see the image in the website.

Leave a comment

Your email address will not be published. Required fields are marked *