SugarCRM SupportProduct GuidesSugar DeveloperSugar Developer Guide 11.0CookbookPassing Data to Templates

Passing Data to Templates


This page explains how to create a custom view component that passes data to the Handlebars template.

Steps to Complete

The view component will render the actual content on the page. The view below will display data passed to it from the controller.


    className: 'tcenter',
    loadData: function (options) {
        //populate your data
        myData=new Object();
        myData.myProperty = "My Value";
        this.myData = myData;
            //alternatively, you can pass in a JSON array to populate your data
            myData = $.parseJSON( '{"myData":{"myProperty":"My Value"}}' );
            _.extend(this, myData);


        //reset flags on reload
        if (options && _.isFunction(options.complete)) {
        // Another Alternative you can get the date from an end point
        let self = this;"read", app.api.buildURL("Accounts/4bbd3b4e-755d-11e9-9a7b-f45c89a8598f"), null, {
            success: function (accountResponse) {
                self.myData['account'] = accountResponse;


Next, add the Handlebars template to render the data. An example is shown below:


{{#with myData}}
 {{}} - {{account.assigned_user_name}} <br>

Once the files are in place, add the view to a layout and then navigate to Admin > Repair > Quick Repair and Rebuild.

Last modified: 2021-02-17 02:44:13