Rickname
90
2019-01-22 16:08:19
0
490

Handlebars 헬퍼가 등록되지 않습니다.


현재 스프링부트로 개발하고 있습니다.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Handlebar.js Template</title>
<script src="webjars/jquery/2.2.1/jquery.js"></script>
<script src="webjars/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script src="webjars/handlebars/4.0.11-1/handlebars.js"></script>

</head>
<body>
<div id="pagination"></div>

<script id="pagination-template" type="text/x-handlebars-template">
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
<li class="page-item"><a class="page-link" href="?page={{sub Page.number}}">{{sub Page.number}}</a></li>
<li class="page-item"><a class="page-link" href="?page={{Page.number}}">{{Page.number}}</a></li>
<li class="page-item"><a class="page-link" href="?page={{add Page.number}}">{{add Page.number}}</a></li>
</ul>
</nav>
</script>

<script type="text/javascript">
var psource = $("#pagination-template").html();
var template = Handlebars.compile(psource);
Handlebars.registerHelper('add', function (number) {
return number + 1;
});
Handlebars.registerHelper('sub', function (number){
return number - 1;
});
$("#pagination").html(template);
</script>

</body>
</html>

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Jan 22 16:02:33 GMT+09:00 2019
There was an unexpected error (type=Internal Server Error, status=500).
com.github.jknack.handlebars.HandlebarsException: classpath:templates/test.hbs:19:98: could not find helper: 'sub' <li class="page-item"><a class="page-link" href="?page={{sub Page.number}}">{{sub Page.number}}</a></li> ^


위와 같은 오류 메시지가 계속 뜹니다.

문제되는 코드(등록한 헬퍼를 사용한 부분)을 빼고 빌드했을 때는 문제없이 됩니다.

Handlebars 문법에 틀린 부분이 있나요??

0
0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.