2014-06-26 60 views
-1

這裏的想法:#if field == req.locals.variable,render handlebars template?

{#if creatorField == req.locals.user) 
    <div class="thisHTML">{{ story }}</div> 
{else} 
    <div class="thatHTML">{{ story }}</div> 
{/if} 

如果creatorField不匹配req.locals.user值,然後採用不同的HTML模板將使。這是內置的功能,還是需要某種助手?

+0

[Handlebars Helper for rendering template if creatorField == req.locals.user?](http://stackoverflow.com/questions/24422333/handlebars-helper-for-rendering-template-if-the -creatorfield-req-locals-user) –

回答

1

邏輯應保留在您的控制器中,因此您的Handlebars上下文中的布爾結果爲creatorField == req.locals.user,而不是在模板內計算它,然後只使用內置的if block helper

+0

謝謝,這是有道理的..將盡快測試並接受 – StackThis