简体   繁体   English

ApostropheCMS-以快速路线呈现完整的HTML页面

[英]ApostropheCMS - Rendering a full HTML page in express route

I created a new page(extends apostrophe-custom-pages) and created several POST-routes in it. 我创建了一个新页面(扩展了撇号自定义页面)并在其中创建了多个POST路由。 They're named exactly like some other regular pages and should handle only the POST-requests. 它们的命名与其他常规页面完全一样,并且仅应处理POST请求。

This code works very well and renders the empty layout: 该代码可以很好地工作并呈现空白布局:

module.exports = {
    extend: 'apostrophe-custom-pages',
    afterConstruct: function (self) {
        self.apos.app.post('/xyz', self.handlePostRequest);
    },
    construct: function (self, options) {
        self.handlePostRequest = (req, res) => {
            // Do some stuff

            return self.sendPage(req, self.renderer('layout'), () => ({
                'success': false
            }));
        }
    }
};

Now i want to simply render the same page as it's delivered by a GET-request with some variables assigned to the view(eg "success" => false). 现在,我想简单地渲染与GET请求提供的页面相同的页面,并为该页面分配一些变量(例如,“成功” => false)。

self.apos.app.get('foo', self.handleGetRequest);

followed by: 其次是:

self.handleGetRequest = (req, res) => {
  // Do some stuff
  return self.sendPage(req, self.renderer('layout'), { foo: 'bar' });
}

You'll then have {{ data.foo }} available in your layout.html file. 然后,您的layout.html文件{{ data.foo }}提供{{ data.foo }}

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

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