Node.js keystone.js当前已登录用户
我是Keystone的新手,但我整天都在努力寻找当前登录的用户名,但我不清楚如何做到这一点 以keystone的索引视图为例Node.js keystone.js当前已登录用户,node.js,handlebars.js,keystonejs,Node.js,Handlebars.js,Keystonejs,我是Keystone的新手,但我整天都在努力寻找当前登录的用户名,但我不清楚如何做到这一点 以keystone的索引视图为例 {{!< default}} <div class="container"> <div class="jumbotron"><img src="/images/logo.svg" width="160"> <h1>Welcome</h1> <p>This
{{!< default}}
<div class="container">
<div class="jumbotron"><img src="/images/logo.svg" width="160">
<h1>Welcome</h1>
<p>This is your new <a href='http://keystonejs.com' target='_blank'>KeystoneJS</a> website.</p>
<p>
It includes the latest versions of
<a href='http://getbootstrap.com/' target='_blank'>Bootstrap</a>
and <a href='http://www.jquery.com/' target='_blank'>jQuery</a>.
</p>
<p>Visit the <a href='http://keystonejs.com/guide' target='_blank'>Getting Started</a> guide to learn how to customise it.</p>
<hr>
<p>We have created a default Admin user for you with the email <strong>masterofimps@yahoo.co.uk</strong> and the password <strong>admin</strong>.</p>
<p><a href="/keystone/signin" style="margin-right: 10px" class="btn btn-lg btn-primary">Sign in</a> to use the Admin UI.</p>
<hr>
<p>
Remember to <a href='https://github.com/keystonejs/keystone' target='_blank'>Star KeystoneJS on GitHub</a> and
<a href='https://twitter.com/keystonejs' target='_blank'>follow @keystonejs</a> on twitter for updates.
</p>
</div>
</div>
{{!
它包括最新版本的
和。
访问指南了解如何定制它
我们已使用电子邮件为您创建了默认管理员用户masterofimps@yahoo.co.uk和密码admin
使用管理用户界面
记得去和
在twitter上获取更新。
我想在视图代码中添加用户名,比如
<h1>Welcome Tim</h1>
欢迎蒂姆
我试过了
<h1>Welcome {{locals.user}}</h1>
<h1>Welcome {{locals.user.name}}</h1>
<h1>Welcome {{req.user}}</h1> (using an Express request)
欢迎{{locals.user}
欢迎{{locals.user.name}
欢迎{{req.user}}(使用快速请求)
但是没有用。如何从用户模型中找到用户名?是否必须先在..\routes\View中定义其他内容
如果有人能提供一个正确方向的例子或指针,我将非常感激 如果使用Yeoman生成器,则包含的一个中间件函数(
initLocals
)将当前用户设置为局部变量
res.locals.user = req.user;
您不需要在Handlebar中的变量名称之前包含局部变量
。因此,删除它以获取当前用户信息
{{user}}
{{user.name}}
如果使用的是Yeoman生成器,则包含的一个中间件函数(
initLocals
)将当前用户设置为局部变量
res.locals.user = req.user;
您不需要在Handlebar中的变量名称之前包含局部变量
。因此,删除它以获取当前用户信息
{{user}}
{{user.name}}
先生,你真棒。在仔细阅读了中间件代码之后,我想我现在明白了。先生,你太棒了。在更仔细地阅读了中间件代码之后,我想我现在明白了。