Document Properties
Kbid2G8047
Last Modified24-Jun-2020
Added to KB28-Oct-2016
Public AccessEveryone
StatusOnline
Doc TypeGuidelines, Concepts & Cookbooks
Product
  • ICM 7.8
  • ICM 7.9
  • ICM 7.10

Concept - JavaScript Intershop Handlebars Controller


1 Introduction

The JavaScript class ishHbsController was introduced to ease working with the Handlebars Template Engine.

1.1 References

2 Methods

2.1 init

init()

Initialize the controller and precompile the handlebars template

Description:

Initialize the Handlebars controller and precompile the handlebars template for rendering.
The complete initialization process will be triggered by the ISML module ishbs.
Therefore the init() method is not needed to be called by the developer.

Parameter List:

  • none

Returns

  • No return parameters

Example

/*
	Example for the template snippet in any ISML template:
	<script id="SubscriptionsList" type="text/x-handlebars-template">
		<h3>{{title}}</h3>
	</script>
*/
 
SubscriptionsListController = new ishHbsController('SubscriptionsList'); 
SubscriptionsListController.init();
SubscriptionsListController.controller(function() {
	// ... custom controller code
});

2.2 debug

debug()

Set the internal debug parameter

Description:

An internal debugging parameter will be set to true.
So the developer will see at console output which controller will be executed. 
The method is chainable. 

Parameter List:

  • none

Returns

  • Returns the current instance of the controller itself. So the method is chainable.

Example

SubscriptionsListController = new ishHbsController('SubscriptionsList'); 
SubscriptionsListController.debug();
SubscriptionsListController.init();
SubscriptionsListController.controller(function() {
	// ... custom controller code
});
var controller = this;
controller
	.debug()

	.model({ ... })
	.update();

2.3 model

model( <data> )

Update the model data

Description:

Update the model data.
The method is chainable. 

Parameter List:

  • data (optional)
    Defines the model data in form of a JSON object.

Returns

  • Using as setter method (parameter data is provided):
    • Returns the current instance of the controller itself. So the method is chainable.
  • Using as getter method (no parameter is provided):
    • Returns the model data.

Example

SubscriptionsListController = new ishHbsController('SubscriptionsList'); 
SubscriptionsListController.init();
SubscriptionsListController.model({
	"title": "...",
	"subtitle": ".................."
});

2.4 update

update()

Update the precompiled Handlebars template

Description:

Update the precompiled Handlebars template with the current model.
The method is chainable. 

Parameter List:

  • none

Returns

  • Returns the current instance of the controller itself. So the method is chainable.

Example

SubscriptionsListController.update();

2.5 controller

controller( <handler> )

Customized user controller code for the current Handlebars controller instance

Description:

Set the customized user controller handler code for the current Handlebars controller instance and execute the handler.
The method is chainable. 

Parameter List:

  • handler
    Customized user controller code for this Handlebars controller

Returns

  • Returns the current instance of the controller itself. So the method is chainable.

Example

SubscriptionsListController.controller(function() {
	// ... custom controller code
});

2.6 extend

extend( <methods> )

Customized user methods for the current Handlebars controller instance

Description:

Extends the current controller instance with customized user methods.
The method is chainable. 

Parameter List:

  • methods
    Customized user methods with all defined methods

Returns

  • Returns the current instance of the controller itself. So the method is chainable.

Example

SubscriptionsListController.extend({
	method1: function() {
	},
	method2: function() {

	}
});

2.7 filterElements

filterElements( <handler>, <model> )

Method to filter the current model data

Description:

This method helps to filter the current model elements data by a specific filter handler.
The original model data will not be touched.
The method is chainable. 

Parameter List:

  • handler
    Filter handler function to manipulate the current model data
  • model (optional)
    If set the original model will be updated before the filter will be applied 

Returns

  • Returns the current instance of the controller itself. So the method is chainable.

Example

// Example for a filter handler to filter all items where the string "Max" is found on the name value
subscriptionsListController.filterElements(function(item) {
	
   	if (item.name.toLowerCase().indexOf('Max') != -1) {
   		return true;
   	}else{
   		return false;
	}
	
});
 
// Example to remove the current filter and use the original model data
subscriptionsListController.filterElements(false);

2.8 filteredModel

filteredModel( <model> )

Getter and setter for the currently filtered model data

Description:

This method updates the current filtered model data.
The original model data will not be touched.
The method is chainable. 

Parameter List:

  • model (optional)
    Defines a JSON object with the data

Returns

  • Using as setter method (model parameter provided):
    • Returns the current instance of the controller itself. So the method is chainable.
  • Using as getter method (no parameter provided):
    • Returns the filtered model data.

Example

// Example for a filter handler to filter all items where the string "Max" is found on the name value
subscriptionsListController.filteredModel({
	"title": "...",
	"subtitle": ".................."
});


Disclaimer

The information provided in the Knowledge Base may not be applicable to all systems and situations. Intershop Communications will not be liable to any party for any direct or indirect damages resulting from the use of the Customer Support section of the Intershop Corporate Web site, including, without limitation, any lost profits, business interruption, loss of programs or other data on your information handling system.

Customer Support
Knowledge Base
Product Resources
Support Tickets