2012-07-16 3 views

답변

12

포인트 백본. 헨들바를 컴파일하는 템플릿. 이 당신의 main.js에 수행 할 수 있습니다

require.config({ 

    // Initialize the application with the main application file 
    deps: ["main"], 

    paths: { 

    libs: "../assets/js/libs", 
    plugins: "../assets/js/plugins", 

    // Libraries 
    jquery: "../assets/js/libs/jquery", 
    underscore: "../assets/js/libs/lodash", 
    backbone: "../assets/js/libs/backbone", 
    marionette: "../assets/js/libs/backbone.marionette", 
    handlebars: "../assets/js/libs/handlebars", 

    //plugins 
    text : "../assets/js/plugins/text", 
    i18n : "../assets/js/plugins/i18n", 

    }, 

    config: { 
     //Set the config for the i18n 
     //module ID 
     i18n: { 
      locale: 'fr-fr' 
     } 
    }, 

    shim: { 

    marionette: { 
     deps: ['backbone'], 
     exports: 'Backbone.Marionette' 
    }, 

    backbone: { 
     deps: ["underscore", "jquery"], 
     exports: "Backbone" 
    }, 

    handlebars: { 
     deps: [], 
     exports: "Handlebars" 
    } 

    } 
}); 

이 중 하나에서 사용이 귀하의 config.js에 수행 할 수 있습니다 :

Backbone.Marionette.TemplateCache.prototype.compileTemplate = function(rawTemplate) { 

     return Handlebars.compile(rawTemplate); 
    }; 

구성 앱이 핸들과 국제화를 사용하는 당신의 모듈 :

define([ 

    'jquery', 
    'underscore', 
    'backbone', 
    'marionette', 
    'handlebars', 
    'text!templates/template.html', 
    'i18n!nls/your_i18n_text' 
], 

function($, _, Backbone, Marionette, Handlebars, tmpl, msg) { 

    'use strict'; 

    var mod = Backbone.Model.extend({ 

     defaults: function() {   
       return {      
        feedUrl : "this is for test" 
       }; 
     } 

    }); 

    view = Backbone.Marionette.ItemView.extend({ 

    template: Handlebars.compile(tmpl), 

    model: new mod(), 

    initialize: function() { 

     this.tmpl_data = msg;  
     if(msg && this.model) 
      this.tmpl_data = _.extend(this.model.toJSON(),msg); 
    }, 

    render: function() { 

     var view = this; 

     $(this.el).html(this.template(view.tmpl_data)); 
     return this; 
    } 

    }); 


}); 

이 템플릿 + 국제화 (i18n) 파일을 가져오고

를 렌더링
2

당신이 (나를 위해 레일에 루비를) 어떤 서버 측 프레임 워크를 사용할 수 있도록 내가 모든 불가지론이다 i18n-JS를 사용하고 (나를 위해 HAML 커피) 모든 자바 스크립트 템플릿 엔진.

%form.form-horizontal 
    .modal 
    .modal-header 
     %button{ class: 'close', data: { dismiss: 'modal' } } × 
     %h3 
     = I18n.t(@property.get('name'), scope: 'data_sheets.properties') 

    .modal-body 
     - unless @property.get('editable') 
     %p= I18n.t('data_sheets.you_already_contributed_to_this_property') 

그래서 등뼈 나 마리오네트 측에 대해 아무런 상관이 없다 : 여기에

은 예입니다.