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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:19:22+00:00 2026-06-06T21:19:22+00:00

im trying to use templates for my backbone views. I tried it with underscore.template

  • 0

im trying to use templates for my backbone views. I tried it with underscore.template to get it running. The problem is that since the manifest_version 2 of chrome extensions there are some security restrictions. I think the reason is because inline blocks are not allowed anymore. In this little example i load a template and try to render it. I then get the error:

Uncaught Error: Code generation from strings disallowed for this context.

I tried it also with Handlebars.js and a template right into my html-file. It works in a normal browser-window. But it does not as a chrome extension.

So how can i use templates with backbone.js in a chrome extension with manifest_version 2?

With underscore (does not work):

define [
  'jquery'
  'backbone'
  'lib/facade'
  'text!templates/loginTemplate.js'
],
($, Backbone, facade, LoginTemplate) ->
  'use strict'
  class LoginView extends Backbone.View
    tagName: 'div'
    events: {

    }

    initialize: (options) ->
      @el = options.el

    render: ->
      console.log 'LoginView: render()'
      $(@el).html(_.template(LoginTemplate, {}))

with handlebars (does not work):

template in index.html:

<!-- templates -->
  <script id="loginTemplate" type="text/x-handlebars-template">
    <form class="form-horizontal">
      <fieldset>
        <legend>Login</legend>
        <div class="control-group">
          <label class="control-label" for="email">Email:</label>
          <div class="controls">
            <input type="text" class="input-xlarge" id="email" name="email">
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="password">Passwort:</label>
          <div class="controls">
            <input type="password" class="input-xlarge" id="password" name="password">
          </div>
        </div>
        <div class="form-actions">
          <button type="submit" class="btn btn-primary">Login</button>
        </div>
      </fieldset>
    </form>
  </script>

and in my view:

define [
  'jquery'
  'backbone'
  'lib/facade'
],
($, Backbone, facade) ->
  'use strict'
  class LoginView extends Backbone.View
    tagName: 'div'    
    events: {

    }

    initialize: (options) ->
      @el = options.el

    render: ->
      console.log 'LoginView: render()', $("#loginTemplate")
      $(@el).html(Handlebars.compile($("#loginTemplate").html()))
  • 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-06T21:19:23+00:00Added an answer on June 6, 2026 at 9:19 pm

    Both Underscore and Handlebars templates convert strings to JavaScript functions; for example, Underscore does it like this:

    source = "var __t,__p='',__j=Array.prototype.join," +
      "print=function(){__p+=__j.call(arguments,'')};\n" +
      source + "return __p;\n";
    
    var render = new Function(settings.variable || 'obj', '_', source);
    

    so it builds some JavaScript and uses new Function to build a function; Handlebars probably does something similar. Apparently Chrome doesn’t want you doing things like that in an extension.

    You could precompile the template and then embed the function in your extension as a simple bit of JavaScript. For Underscore templates, you could look at the source property:

    The source property is available on the compiled template function for easy precompilation.

    <script>
      JST.project = <%= _.template(jstText).source %>;
    </script>
    

    So you can t = _.template(your_template) while packaging your extension and put the t.source text in your extension as a JavaScript function.

    You can do similar things with Handlebars (see handlebars_assets for example).

    Both of them complicate your build and packaging process but if Chrome doesn’t want you building functions in an extension then there’s not much you can do about it.

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

Sidebar

Related Questions

I'm trying to use backbone.js with underscore.js templates in an asp.net web forms application
Problem: I am trying to use knockout.js with jquery templates. The problem is that
I'm trying to use templates to get std:list of items, where each item has
I'm trying to use friend functions to overload << and templates to get familiar
I'm trying to use Backbone.js to in a JQuery Dialog. I've managed to get
I'm trying to use the T4 templates in my MVC project. This screencast suggests
I am trying to accomplish a module where i need to use nested templates
As documented here: http://www.jblotus.com/2011/05/24/keeping-your-handlebars-js-templates-organized/ I am trying to use this function: ( function getTemplateAjax(path,
I'm going a little nuts trying to figure out how to use template inheritance
I'm trying to use coffeekup as my default template app.set 'view engine', 'coffee' app.register

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.