Drupal 8获取内容并在没有页眉/页脚的情况下投放 [英] Drupal 8 fetch content and serve without header/footer

查看:76
本文介绍了Drupal 8获取内容并在没有页眉/页脚的情况下投放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个Drupal 8网站上工作,在那里我有一个自定义模块/块,该模块/块可从另一台服务器获取内容并将其注入到div中。
当用户单击注入内容中的链接(如阅读更多内容)时,我需要在没有模板的页眉和页脚的情况下提供内容(完整的html页)(从服务器获取)。

I'm working on a Drupal 8 site where I have a custom module/block that fetches content from another server and injects it to a div. When a user clicks on a link (like read more) from the injected content, I need to serve the content (full html page) (that gets fetched from the server) without my template's header and footer.

我的问题是我如何在没有模板的页眉和页脚的情况下提供页面?

My question is how can I serve a page without my template's header and footer?

谢谢。

推荐答案

这是一个老问题,但是它正在搜索中出现,我想发布一个解决方案。如果您只想提供一些自定义HTML,请包括Symfony HTML响应类并调用返回一个Response对象。

This is an old question but it's coming up in searches and I wanted to post a solution. If you want to serve just some custom HTML include the Symfony HTML response class and call return a Response object. This will output only the HTML you provide.

use Symfony\Component\HttpFoundation\Response;

Class YourController extends ControllerBase {
  public function pageFunction() {
    return new Response('<html><div>test</div></html>');
  }
}

这篇关于Drupal 8获取内容并在没有页眉/页脚的情况下投放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆