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 8949295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:11:23+00:00 2026-06-15T13:11:23+00:00

Rendering templates is a piece of cake when the data displayed within the template

  • 0

Rendering templates is a piece of cake when the data displayed within the template is either internationalized text OR model attributes, but when it comes to rendering BOTH within one template, I can’t seem to find a clean solution.

For reference, I’m utilizing i18n via Require.js’s i18n plugin.

Let’s assume I have a simple template:

<h3>{{displayText.load}} #{{id}}</h3>

<h4 id="loading-load-data">{{displayText.loadingLoadData}}...</h4>

The displayText object represents i18n text, while the id item represents a Backbone Model attribute.

Using Backbone’s template property on a View, I can do the following in order to render a template with i18n text, but without Model attribute data:

return Backbone.Marionette.ItemView.extend({
    template: function () {
        var compiledTemplate = Handlebars.compileClean(template);

        // localizedText represents the i18n localization object, using the Require.js i18n plugin
        return compiledTemplate(localizedText);
    },
    // some more View properties and methods
});

However, once I want to also display the Model data, this no longer works, primarily due to this being undefined within the template attribute (so I can’t reference this.model.attributes), and it seems that I have to fall back to overriding the render() method, passing both the i18n object AND Model attributes to the template, as such:

return Backbone.Marionette.ItemView.extend({
    template: Handlebars.compileClean(template),
    render: function() {
        var templateParams = _.extend({}, this.model.attributes, localizedText),
            renderedTemplate = this.template(templateParams);

        this.$el.html(renderedTemplate);

        this.bindUIElements();
        this.delegateEvents();

        return this;
    }
});

I’d really love to leave Marionette’s default handling of render() in place, and solely use the template property to render both i18n text AND the Model data. Is this possible?

BONUS: Assuming I DO have to override render(), I’m noticing that while doing so, the this.ui attribute, provided on Marionette Views, no longer wraps each item as a jQuery object. This means that:

this.ui.loadingNotification.show();

stops functioning, throwing an Uncaught TypeError: Object #loading-load-data has no method 'show'. Why is this, and how can I restore proper this.ui jQuery-wrapping functionality?

EDIT: Solved the BONUS; simply have to toss in a this.bindUIElements() call within the render() method to properly bind the elements to the ui hash. See the render() example above.

  • 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-15T13:11:23+00:00Added an answer on June 15, 2026 at 1:11 pm

    SOLVED: So the answer is embarrassingly simple. Turns out you can pass a parameter into the template: property when used as a function, and this parameter represents the Model associated with that View/template:

    template: function (model) {
        var templateParams = _.extend({}, model, localizedText),
            renderedTemplate = Handlebars.compileClean(template);
    
        return renderedTemplate(templateParams);
    },
    

    The render() method then no longer needs to be overwritten, and both i18n text and Model data can be rendered into the template as expected.

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

Sidebar

Related Questions

I'm having trouble rendering out a template, my data looks like this: var data
I want add my control code before rendering template. Example: Have templates: user.html.twig Controller:
EDIT: I'm slightly further along now, but the new issue is around rendering templates.
I'm trying to write a custom rendering template for use in the DisplayForm of
I'm getting a missing template error after I try rendering a partial from a
I am trying to save a simple template to pdf using the rendering plugin,
I have several values I'm rendering as <li> elements on my template and I
Guys, reffering to last post I'm trying to output data while template is instantiated
I'm rendering this Cmenu but the active class isn't showing on the li element
I'm getting the following error: Template error In template /home/mo/python/django/templates/yoga/index.html, error at line 1

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.