0% found this document useful (0 votes)
158 views3 pages

SFRA Code Quick Card: 'Use Strict' 'Server' 'Start'

This document provides an overview of common functions in the SFRA (Salesforce Commerce Cloud) code framework, including how to: - Define basic server routes - Prepend, append, or replace routes using a supermodule - Use middleware scripts and chaining in routes - Call scripts from controllers to retrieve data - Extend models by calling the supermodule - Use template and form decorators, includes, and slots - Set cache values in controllers

Uploaded by

Shashank Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views3 pages

SFRA Code Quick Card: 'Use Strict' 'Server' 'Start'

This document provides an overview of common functions in the SFRA (Salesforce Commerce Cloud) code framework, including how to: - Define basic server routes - Prepend, append, or replace routes using a supermodule - Use middleware scripts and chaining in routes - Call scripts from controllers to retrieve data - Extend models by calling the supermodule - Use template and form decorators, includes, and slots - Set cache values in controllers

Uploaded by

Shashank Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SFRA Code Quick Card

BASIC FUNCTION

'use strict';
//other imports here…
var server = require('server');

server.get('Start', function (req, res, next) {


//other code here…
    next();
    
});
module.exports = server.exports();

PREPEND/APPEND/REPLACE USING SUPERMODULE IN A CONTROLLER

var server = require('server');
server.extend(module.superModule);

server.prepend('Show', function (req, res, next) {
    //This information is inserted before the original Show Route.
    });

server.append('Show', function (req, res, next) {
    //This information is inserted after the original Show Route.
    });

server.replace('Start', function (req, res, next) {
    //This information replaces the original Start Route.
    });

USE MIDDLEWARE SCRIPTS & CHAINING

//Imports the script


var scriptName = require('*/cartridge/scripts/middleware/scriptxyz');

//Invoke the middleware step in the route


server.get('Start', scriptName.middlwareStep, 
    function (req, res, next) {
    //...
});
CALL A SCRIPT IN A CONTROLLER (PRODUCT FACTORIES)

//Imports the script


var VariableName = require('*/cartridge/scripts/scriptxyz');

server.get('Show', function (req, res, next) {
    //gets the querystring parameters from req
    var params = req.querystring;
    //gets the product from ProductFactories 
    var theProduct = VariableName.get(params);
    //…
});

SUPERMODULE CALL() METHOD TO EXTEND MODELS

//defines the base variable to equal module.superModule


var base = module.superModule;

//use call method to assign attribute to the object


function name(nameObject) {
    base.call(this, nameObject);
    this.newAttribute = nameObject.newAttribute;
}
store.prototype = Object.create(base.prototype);

TEMPLATE DECORATOR

<isdecorate template="common/layout/templatename">
</isdecorate>

LOCAL INCLUDE

<isinclude template="templatename"/>

REMOTE INCLUDE

<isinclude url="${URLUtils.url('ControllerName')}" />

CONTENT SLOT

<isslot id=".." description="..." context="..." />

FORM METADATA

<field formid="..." label="..." type="..." binding="..." />
FORM ISML

<div class="form-group notrequired">
    <label class="form-control-label">
        <isprint value="${pdict.parameter}" encoding="htmlcontent" />
     </label>
    <input type="checkbox" class="form-control" id="..." <isprint value="${pdict.param
</div>

SET CACHE IN CONTROLLER

var scriptName = require('*/cartridge/scripts/scriptName');

server.get('Show',scriptName.function, 
    function (req, res, next) {
    res.render('templatename');
    next();
});

You might also like