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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:14:52+00:00 2026-06-15T16:14:52+00:00

I have this code: if (this.template) { var template = Handlebars.compile( $(this.template).html() ); $(this.el).html(template());

  • 0

I have this code:

if (this.template) {
        var template = Handlebars.compile( $(this.template).html() );
        $(this.el).html(template());
    }

with this template:

<script id="tmpl-nav-account" type="text/x-handlebars-template">
{{#this}}
<div class="nav-account">
    topbar
</div>
{{/this}}

However, if run the ‘template()’ function with no params, nothing outputs. Yet, if I pass something in like: “template(‘ben’)”, it outputs the static HTML fine. Anyone got any ideas?

Does template() always have to have something passed into it to render the template?

EDIT:

If I remove the {{#this}} from the template, then it works with no parameters…

  • 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-15T16:14:54+00:00Added an answer on June 15, 2026 at 4:14 pm

    The this at the top level of a template is the argument you supply to the compiled template function. So, given this:

    var o = { ... };
    var t = Handlebars.compile(some_template_text);
    t(o);
    

    this will be o at the top level of the template. So, if you say template(), this is undefined inside the template and {{#this}} won’t do anything because undefined is false in a boolean context.

    You can see this clearly if you use this template:

    <script id="tmpl-nav-account" type="text/x-handlebars-template">
        {{#this}}
            <div class="nav-account">
                {{this.where_is}}
            </div>
        {{/this}}
    </script>​
    

    and this JavaScript:

    var t = Handlebars.compile($('#tmpl-nav-account').html());
    console.log(t());
    console.log(t({ where_is: 'pancakes house?' }));​
    

    Demo: http://jsfiddle.net/ambiguous/fS8c9/

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

Sidebar

Related Questions

I have a template like this: <script id=notesTemplate type=text/html> <li class=Note> <div class=NoteDate data-bind=style:
I have this code: _.templateSettings = {interpolate : /\{\{(.+?)\}\}/g}; var _d = _.template($('#_d').html()); $.get('/foo',
I have javascript code embedded inside a html template file. When I load this
I have this code in the page. <input type=text value=Enter your video URL here...
I have this code which will include template.php file from inside each of these
I have this code inside a header (edited): template <int i> class A {};
I have this code: struct A{}; template<class T = A> struct B { void
I have non-template class with a templatized constructor. This code compiles for me. But
I have the given view and template code, when i try to run this
I have code that looks like this: template<class T> class list { public: class

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.