0% found this document useful (0 votes)
32 views1 page

DEV101 Javascript Controllers Quickcard 8-19-2016

The document provides an overview of common JavaScript controller tasks in Demandware like importing objects, declaring functions, handling forms, redirects, transactions and invoking other scripts. It also describes how to work with query parameters, display forms, write directly to the browser and give control to ISML templates.

Uploaded by

Sofia Ferreira
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)
32 views1 page

DEV101 Javascript Controllers Quickcard 8-19-2016

The document provides an overview of common JavaScript controller tasks in Demandware like importing objects, declaring functions, handling forms, redirects, transactions and invoking other scripts. It also describes how to work with query parameters, display forms, write directly to the browser and give control to ISML templates.

Uploaded by

Sofia Ferreira
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/ 1

JavaScript 

Controllers QuickCard

Import an Object Displaying a Form (Equivalent of ICN node)             
var ISML = require('dw/template/ISML'); ISML.renderTemplate(
'editpreferences.isml', 
var guard = require('storefront_controllers/cartridge/scripts/guard');
{
ContinueURL : dw.web.URLUtils.https('JEditPreferences‐
Function Declaration and Exposure HandleForm'),
function start() { CurrentForms : session.forms
} }
exports.Start = guard.ensure([ 'get'], start); );
exports.Start = guard.ensure([ 'get', 'https', 'loggedIn' ], start);
Submit Button
Dealing with Query Parameters var submitButton = 
var parameterMap = request.httpParameterMap; request.triggeredFormAction.formId;
var parameterId =parameterMap.pid.stringValue;
Writing to Browser Directly
Handling Forms response.getWriter().println(“Hello from controllers”);
/* assuming forms/default/preferences.xml is the metadata */
var preferencesForm = session.forms.preferences;  Explicit Transactions
preferencesForm.clearFormElement(); var Transaction= require('dw/system/Transaction);
preferencesForm.copyFrom(customer.profile); Transaction.begin();
preferencesForm.copyTo(customer.profile); Transaction.commit();
preferencesForm.interestElectronics.value; Transaction.rollback();
preferencesForm.invalidateFormElement(); 

Redirecting to Another Pipeline
Giving Control to ISML (Equivalent of Interaction node) response.redirect(URLUtils.https('Account‐Show'));
ISML.renderTemplate(
'productnotfound.isml', 
{ Invoking a Script (js or ds)
message:'product'+parameterId+'found' var myModel = require('~/cartridge/scripts/MyModel');  
}   var co=myModel.doJobForMe(takeThisObject);
);

© 2016 Demandware, Inc. DEV 101: Developing in Demandware

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy