2016-08-09 3 views
0

Я пытаюсь предварительно скомпилировать мой шаблон дескриптора Home.hbs, но он дает мне сообщение об ошибке, не могу прочитать свойство «имя шаблона» неопределенного.Handlebar.templates is undefined

Вот индексный файл

<!DOCTYPE html> 
<html lang="en"> 
<link> 
<meta charset="UTF-8"> 
<title>Title</title> 
<link href="dist/styles/libs/bootstrap.css"/> 
<link href="dist/styles/app.css"/> 

</head> 
<body> 
<div class="wrapper"> 
    <h1>This is the home page</h1> 

</div> 
</body> 
<script src="dist/js/thirdparty.js"></script> 
<script src="dist/js/templates.js"></script> 
<script src="dist/js/main.js"></script> 

</html> 

Я использую задачу Глоток-руля предварительно скомпилировать его

var config ={ 
    handlebar: { 
      path: 'app/templates/pages/**/*.hbs', 
      dist: 'dist/js', 
      partials: 'app/templates/partials/**/*.hbs' 
    } 
} 
gulp.task('handlebar', function(){ 
    gulp.src(config.handlebar.path) 
     .pipe(handlebars()) 
     .pipe(wrap('Handlebars.template(<%= contents %>)')) 
     .pipe(declare({ 
      namespace: 'RRI.templates', 
      noRedeclare: true, // Avoid duplicate declarations 
     })) 
     .pipe(concat('templates.js')) 
     .pipe(gulp.dest(config.handlebar.dist)); 
}); 

Home.hbs

<div class="entry"> 
    <h1>{{title}}</h1> 
    <div class="body"> 
     {{body}} 
    </div> 
</div> 

<div class="wrapper"> 
    <h2>Hello World!! </h2> 
    {{> _search}} 
</div> 

_search.hbs

<h1>search</h1> 

main.js

$(document).ready(function() { 
    var template = Handlebars.templates.RRI.templates.Home; 
    var context = {title: "My New Post", body: "This is my first post!"}; 
    var html = template(context); 
    $(".wrapper").append(html); 
}); 

Это дает мне ошибку на второй линии в main.js говоря, не может прочитать свойство RRI неопределенной.

template.js файл

this["RRI"] = this["RRI"] || {}; 
this["RRI"]["templates"] = this["RRI"]["templates"] || {}; 
this["RRI"]["templates"]["Home"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { 
    var stack1, helper, alias1=helpers.helperMissing, alias2="function", alias3=this.escapeExpression; 

    return "\r\n\r\n<div class=\"entry\">\r\n <h1>" 
    + alias3(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"title","hash":{},"data":data}) : helper))) 
    + "</h1>\r\n <div class=\"body\">\r\n  " 
    + alias3(((helper = (helper = helpers.body || (depth0 != null ? depth0.body : depth0)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"body","hash":{},"data":data}) : helper))) 
    + "\r\n </div>\r\n</div>\r\n\r\n<div class=\"wrapper\">\r\n <h2>Hello World!! </h2>\r\n" 
    + ((stack1 = this.invokePartial(partials._search,depth0,{"name":"_search","data":data,"indent":" ","helpers":helpers,"partials":partials})) != null ? stack1 : "") 
    + "</div>\r\n"; 
},"usePartial":true,"useData":true}); 

Я использую поручень 3.0.1, пожалуйста, помогите.

ответ

0

Наконец это то, что работает для меня, незначительных изменений в template.js

var template = RRI.templates.Home; 

Я нашел это после некоторой отладки, но это определенно означает, что либо я сделал что-то странное или как рулит Docs не обновляется ,