简体   繁体   中英

Compile only part of a Handlebars.js template

I have a Handlebars.js template that I would like to complile piecemeal, as separate sections of this template correspond to different Backbone.js subviews. Is it possible to compile only the #subsection part of the following template?

<section id="widget">
    <h1>Widget Header!</h1>
    <nav id="nav">
        <!-- blah blah stuff here -->
    </nav>
    <section id="subsection">
        <!-- rah rah more stuff here -->
    </section>
</section>

NOTE: I realize that many of you will wonder why I shouldn't just use a file for each template. Currently I have only one use of this template, so I had no reason to split it up.

Basically, for what you ask, no you cannont render a subsection of an Handlebars template.

What you'll want is probably multiple templates; one for each view. Then you can only rerender the view.

Corectly you need few templates. One template for one subview.

But you can use jQuery (i dont know about zepto).

var html = widgetTemplate(); // your template    
var el = $(html);
var elementForSubvie = el.find('#subsection');

It works, but its bad way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM