menu

SiteGenesis / Server-side JS / Module: app

Methods

(static) getController()

Returns the controller with the given name.

Source:

(static) getForm(formReference) → {module:models/FormModel~FormModel}

Use this method to get a new instance for a given form reference or form object.

Parameters:
Name Type Description
formReference dw.web.FormElement | String

Salesforce form id (/forms/$name$.xml) or Salesforce form object.

Source:
Returns:
Type
module:models/FormModel~FormModel
Example
// simple form preparation
var form = require('~/app').getForm('registration');
form.clear();

// handling the form submit
var form = require('~/app').getForm('registration');
form.handleAction({
    'register' : function(formGroup, action){
        // handle the action here
    },
    'error'    : function(){
        // handle form errors here
    }
});

(static) getModel()

Returns the model for the given name. The model is expected under the models directory.

Source:

(static) getView(viewName, parameters) → {object/View}

Returns a view for the given name. The view is expected under the views directory. If no view exists with this name or if no view name is specified, a default view is returned instead.

Parameters:
Name Type Description
viewName string

The name of the view

parameters object

The parameters to pass to the view

Source:
Returns:

The view object instance

Type
object/View
Example
// use an anonymous view
require('~/app').getView().render('path/to/template');

// or use a named view
var product = dw.catalog.ProductMgr.getProduct('123456');
require('~/app').getView('Product', {
    product : product,
    showRecommendations : false
}).render('path/to/template');