简体   繁体   English

sailsjs将参数传递给常规路线

[英]sailsjs passing parameters to regular route

I have read the documentation about Controllers to generate response in actions. 我已经阅读了有关控制器以在操作中生成响应的文档。 But I am having questions about some other non-controller views. 但是我对其他一些非控制器的观点有疑问。 In the config/views, 在配置/视图中,

'/':{view:'homepage'}

I am wondering, if I want to pass in parameters in to the homepage template, how would I do that? 我想知道,如果要将参数传递到主页模板中,该怎么做?

You can pass variables into your template by setting locals in the route config: 您可以通过在route config中设置locals来将变量传递到模板中:

'GET /': {
  view: 'homepage',
  locals: {
    username: 'foo',
    email: 'foo@bar.com',
    ...etc...
  }
}

This is equivalent to the following in a controller: 这等效于控制器中的以下内容:

res.view('homepage', {username: 'foo', email: 'foo@bar.com'});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM