AnsweredAssumed Answered

Passing data to custom template

Question asked by Sagar Honrao on Apr 5, 2019
Latest reply on Apr 6, 2019 by Alan Apter

I have created custom template, which is added before record layout. Now i want to display dynamic data of related record to that custom template .hbs file.

Below are the my record.js file code, which is overrite by me.

 

/custom/modules/Accounts/clients/base/layouts/record/record.php

<?php
$viewdefs['Accounts']['base']['layout']['record'] = array(
'components' => array(
array(
'layout' => array(
'type' => 'default',
'name' => 'sidebar',
'components' => array(
array(
'layout' => array(
'type' => 'base',
'name' => 'main-pane',
'css_class' => 'main-pane span8',
'components' => array(
array(
'view' => 'custom-template-modulewise', /////////here is custom template added
),
array(
'view' => 'record', //////////here is default record view layout
'primary' => true,
),

.......

 

Below are my custom template's javascript file. In javascript file, i get data from api call which is custom api. And i want to bind that api response to .hbs file.

so here are my javascript file code:

custom/modules/Accounts/clients/base/views/custom-template-modulewise/custom-template-modulewise.js

 

({
extendsFrom: 'RecordView',
className: 'custom-template-modulewise',
initialize: function (options) {
this._super('initialize', [options]);
var self = this;
var url = app.api.buildURL('/Accounts/GetData/'+this.model.get('id')); //This is custom api which is written by me, and it return related account all details.
app.api.call('read', url, null, {
success: function (response) {

self.accountData= response.data; 
self.render();
},
});
},
})

 

My custom api response like this:

{"resp":200,"data":{"date_entered":"2019-03-19 10:34:46","date_modified":"2019-04-02 06:23:14",.....,"related_modules_count":{"total_opportunities":3,"total_bugs":0,.....}

 

And here is my .hbs file code, where i want to show dynamic data.

custom/modules/Accounts/clients/base/views/custom-template-modulewise/custom-template-modulewise.hbs

 

<div>
<div class="box red text-white bold">
{{accountData}}
</div>
</div>

 

Any one help me, to show this data to template.

Outcomes