2017-03-28 49 views
1

我使用Node.js,Express和Handlebars爲模板引擎創建登錄驗證應用程序。Handlebars和Node.js:{{#if!user}}然後顯示登錄按鈕

如果沒有用戶登錄,我希望我的儀表板顯示「登錄」按鈕。如果用戶登錄,我不希望它顯示。我試過這個沒有登錄...

{{#if user}} 
    <a type = "button" class = "btn btn-default" href = "https://stackoverflow.com/users/login">Log In</a> 
{{/if}} 

有趣的是,這隱藏了元素。然後,當我糾正了代碼,它應該是...這...

{{#if !user}} 
    <a type = "button" class = "btn btn-default" href = "https://stackoverflow.com/users/login">Log In</a> 
{{/if}} 

我得到這個錯誤,

enter image description here

我以前從來沒有,所以我用車把一種盲目的拍攝。任何幫助提前感謝!

+2

你會想要使用內置的助手。在這種情況下,不要說'{{#if!user}}'應該使用'{{#unless user}}'。 http://handlebarsjs.com/builtin_helpers.html - 你也可以創建你自己的幫手:http://handlebarsjs.com/block_helpers.html – iamjpg

回答

相關問題