Note that there are some explanatory texts on larger screens.

plurals
  1. POExtJS XTemplates: calling a template from another template
    primarykey
    data
    text
    <p>I am trying to avoid redundacy and call a generic XTemplate to format the date and time in GMT from a timestamp.</p> <p>This does not output the string i expect but just [Object object] in the UI.</p> <pre><code>SCB.RMWB.templates = { timeStamp: function(stamp) { return new Ext.XTemplate( '&lt;span class="time-frame"&gt;{[ this.dateRangeMsg(stamp) ]}&lt;/span&gt;', { dateRangeMsg: function(stamp) { console.log('stamp', stamp); var dateTime = new Date(), now = Ext.Date.format(dateTime, 'U'), // gives us seconds since the UNIX Epoch from Ext.Date class offset = Ext.Date.format(dateTime, 'Z'), // gives us GMT offset from Ext.Date class minutesAgo = (now - 300), // 5 minutes ago hourAgo = (now - 3600), // one hour ago msg = ''; if (stamp &gt;= minutesAgo &amp;&amp; stamp &lt;= now) { msg = 'Moments ago'; } else if (stamp &gt;= hourAgo &amp;&amp; stamp &lt;= now){ msg = '1 hour ago'; } else { msg = this.formatGMT(stamp, offset).toString(); } return msg; }, formatGMT: function(stamp, offset){ var time; // * 1000 gives us date string to format in Ext.Date class if (offset &gt; 0){ time = new Date((stamp - offset) * 1000); } else { time = new Date((stamp + offset) * 1000); } return Ext.Date.format(time, 'd-M-y, H:i \\G\\M\\T'); } } ); }, notifications: { flyout: function(){ return new Ext.XTemplate( '&lt;tpl for="."&gt;', '&lt;li id="notification-flyout-{id}"&gt;', '&lt;div class="data-details"&gt;', '&lt;p&gt;{message}&lt;/p&gt;', '{[ this.renderTimeStamp(values.sentDate) ]}', '&lt;/div&gt;', '&lt;/li&gt;', '&lt;/tpl&gt;', { renderTimeStamp: function(stamp) { return SCB.RMWB.templates.timeStamp(stamp); } } ); } } }; </code></pre> <p>If i keep the timestamp functions in the original template it works fine but this functionality will be used in several places in different templates so i would like something more generic i can re-use.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload