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

  • Home
  • SEARCH
  • 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 8566789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:44:11+00:00 2026-06-11T17:44:11+00:00

In this hello world example of a Backbone app http://arturadib.com/hello-backbonejs/docs/5.html , the author renders

  • 0

In this “hello world” example of a Backbone app http://arturadib.com/hello-backbonejs/docs/5.html, the author renders a template inline like this

render: function(){
      $(this.el).html('<span style="color:black;">'+this.model.get('part1')+' '+this.model.get('part2')+'</span> &nbsp; &nbsp; <span class="swap" style="font-family:sans-serif; color:blue; cursor:pointer;">[swap]</span> <span class="delete" style="cursor:pointer; color:red; font-family:sans-serif;">[delete]</span>');
      return this; // for chainable calls, like .render().el
    },

which, although functional, is a bit of an unmanageable html concatenation.

I’ve seen authors of other Backbone apps set a template in the view using underscore’s template function

template: _.template($('#my-template').html()),

and then render it instead of the html

$(this.el).html(this.template(this.model.toJSON()));

I wanted to try this technique with the hello world app, but when I created the template file, I ran into the problem that it wasn’t strictly html. As you’ll notice it calls functions

 this.model.get('part2')

and the template that I was using as a model (from another author’s app, see below) just included html.

Question, What would I need to do to include javascript and html in the same template file so I can make a call to the model?

<script type="text/template" id="item-template">
      <div class="company">
        <div class="display">
          <span class="company-text"></span>
          <span class="company-mood">
            <span class="mood"></span>
          </span>
          <span class="company-destroy"></span>
        </div>
        <div class="edit">
          <input class="company-input" type="text" value="" />
        </div>
      </div>
    </script>
  • 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-11T17:44:12+00:00Added an answer on June 11, 2026 at 5:44 pm

    See this link Underscore Template for details on what you want to accomplish.

    But in general, if you just wanted to interpolate your this.model.get('someAttr'); all you’d need to do is include this in your template.

    // Since you call it like this:
    $(this.el).html(this.template(this.model.toJSON()));
    
    // Just include this
    <div>
        <%= someAttr %>
    </div>
    

    You’re basically passing in the model attributes object and the underscore template just interpolates the properties of that object. You can pass in anything you want although what you do with the render call is what’s probably most common.

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

Sidebar

Related Questions

I'm following this tutorial to create a simple Hello World extension for Chrome: http://code.google.com/chrome/extensions/getstarted.html
In this Hello World example: // Load the http module to create an http
I am trying to run the simplest Hello World example app and looks like
The Hello World example from SLF4J is not working for me. I guess this
In a GWT hello world example, if I compile and run the app, the
For the Hello World example in android.com , the package name is package com.example.helloandroid;
If I have 2 files each with this: Hello World (x 1000) Does that
I have a textbox where a user puts a string like this: hello world!
I have a C++ DLL with code like this: LogMessage( Hello world ); try
My string looks like this $string_value = /hello/world/this/feels/great/ how can I trim world and

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.