Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9015493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:45:51+00:00 2026-06-16T03:45:51+00:00

I am trying to avoid redundacy and call a generic XTemplate to format the

  • 0

I am trying to avoid redundacy and call a generic XTemplate to format the date and time in GMT from a timestamp.

This does not output the string i expect but just [Object object] in the UI.

SCB.RMWB.templates = {
    timeStamp: function(stamp) {
        return new Ext.XTemplate(   
            '<span class="time-frame">{[ this.dateRangeMsg(stamp) ]}</span>',   
            {
                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 >= minutesAgo && stamp <= now) {
                        msg = 'Moments ago';
                    } else if (stamp >= hourAgo && stamp <= 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 > 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(
                '<tpl for=".">',    
                    '<li id="notification-flyout-{id}">',
                        '<div class="data-details">',
                            '<p>{message}</p>',
                            '{[ this.renderTimeStamp(values.sentDate) ]}',   
                        '</div>',   
                    '</li>',   
                '</tpl>',
                {
                    renderTimeStamp: function(stamp) {
                        return SCB.RMWB.templates.timeStamp(stamp);
                    }               
                }
            );
        }
    }
};

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:45:52+00:00Added an answer on June 16, 2026 at 3:45 am

    Well I have some difficulties to follow you within your code example but it should work for you when you call apply on your template instance.

    In detail:

    Create the template you want to reuse once within a helper-namespace. To reuse it provide a method that get’s that instance along with provided data.

    var tpl = new Ext.Template('Name: {name}, Age: {age}');
    tpl.apply({name: 'John', age: 25}); // returns a html string
    

    Here a (more detailed) JSFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm probably over-thinking this/wasting time trying to avoid a bit of conditional code -
Trying to avoid the FxCop warning 'Do not raise reserved exceptions' from a C++/CLI
I am trying to avoid filesort but not getting luck in removing it from
Also trying to avoid any use of plugins, (apart from jQuery of course, whether
In trying to avoid deadlocks and synchronize requests from multiple services, I'm using ROWLOCK,
I'm trying to avoid the N+1 queries problem with eager loading, but it's not
i am trying to avoid the wait time, taken by sending an email before
I am trying to avoid using intents and activities within tabhost and tabwidget This
I'm trying to avoid reinstalling Eclipse to solve this , so I hope someone
I'm trying emerging them(php mysql connection) to avoid from redundancy. But the major problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.