Drupal 8 fetch content and serve without header/footer

纵饮孤独 提交于 2019-12-07 20:57:44

问题


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?

Thanks you.


回答1:


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>');
  }
}



回答2:


You can make a custom page, and in admin/structure/block you remove the blocks from header and footer from that url.

Or you make a custom page template and you remove the print of the header and footer.

File nameing: node--[content-type].html.twig ex: node--article.html.twig node--[content-type]--[display-format].html.twig, ex: node--article--full.html.twig

https://www.drupal.org/node/2282025

Hope I was helpful, please ask if you need further details.



来源:https://stackoverflow.com/questions/38024507/drupal-8-fetch-content-and-serve-without-header-footer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!