2012-10-11 1 views
0

기본적으로 이것은 내 코드이며 반복됩니다. have_last_attr을 두 번 사용하면 작동하지 않습니다 (if 내부). 어떻게 관리 할 수 ​​있을까요?템플릿 헬퍼를 "확인한 경우"템플릿의 반환 값을 사용하려면 어떻게해야합니까?

# .html 
{{#if have_last_attr}} 
    <h3>Last attribute was {{last_attr}}</h3> 
{{/if}} 

# .js 
Template.game.have_last_attr = function(){ 
    var game_id = Session.get('current_game'), 
     game = Games.findOne(game_id), 
     attr = game['last_attr']; 

    return TRANSLATE[attr]; 
}; 

Template.game.last_attr = function(){ 
    var game_id = Session.get('current_game'), 
     game = Games.findOne(game_id), 
     attr = game['last_attr']; 

    return TRANSLATE[attr]; 
}; 

미리 감사

답변

1

에 당신은 {{#with ...}} 문 (handlebars doc)를 사용할 수 있습니다. 적어도이 일을 두 번하고 싶지 않으면 내가하는 일이다. ...

{{#with last_attr}} 
    {{#if this}} 
     <h3>Last attribute was {{this}}</h3> 
    {{/if}} 
{{/with}} 
관련 문제