1

엔진 : https://github.com/tbranyen/backbone.layoutmanager#readmebackbone.layoutmanager 및 핸들 템플릿 나는 backbone.layoutmanager 프로젝트 사용하고

어떤 사람이 핸들 템플릿 엔진과 샘플을 게시하시기 바랍니다 수 있습니까? 수정 된 app.js 파일과 인스턴스보기가 포함 된 ?

나는 지침을 따라 왔고 나는 인스턴스 레벨과 글로벌에서 무엇을해야하는지 혼란 스럽다. 내가 점점 계속 "내 템플릿에는 방법 '일치'ERR 메시지가 없습니다

감사

+0

코드를 게시하여 보시고 도움을 받으실 수 있습니다. –

답변

5

귀하의 수정 app.js는 이런 식으로 작동합니다.

define([ 
    "jquery", 
    "underscore", 
    "backbone", 
    "handlebars", 
    "plugins/backbone.layoutmanager" 
], 
function($, _, Backbone, Handlebars) { 
    "use strict"; 

    var JST = window.JST = window.JST || {}; 

    Backbone.LayoutManager.configure({ 
    paths: { 
     layout: "path/to/layouts/", 
     template: "path/to/templates/" 
    }, 

    fetch: function(path) { 
     path = path + ".html"; 

     if(!JST[path]) { 
     $.ajax({ url: "/" + path, async: false }).then(function(contents) { 
      JST[path] = Handlebars.compile(contents); 
     }); 
     } 

     return JST[path]; 
    } 

    // It is not necessary to override render() here. 
    }); 

    var app = { 
    // Define global resources here. 
    }; 

    return _.extend(app, Backbone.Events); 
}); 

의 예 보기 :

var SampleView = Backbone.View.extend({ 
    template: "path/to/sample/template", 

    // Override this for fine grained control of the context used by the template. 
    serialize: function() { 
    return { 
     property: 1, 
     anotherProperty: 2 
    }; 
    } 

    // No need to override render() for simple templates. 
}); 

그리고보기와 관련된 템플릿 :

,
<div> 
    <h2>{{property}}</h2> 
    <h2>{{anotherProperty}}</h2> 
</div>