4

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.

chatu
  • 305
  • 5
  • 13
  • Are you opening the content in a modal or on a separate page? If it's a separate page, can you have the module be pulling in the content onto a page with a content type specific to the injected content. Then you could write a hook for a page template per that content type and remove the header/ footer. – rachel Jun 25 '16 at 03:13
  • It's a separate page. Can you give me some direction on content type and hooks? Thanks – chatu Jun 25 '16 at 03:26
  • 1
    https://www.drupal.org/node/2521876 Should be able to copy the code there and change to your theme.
    So basically, create a content type only used for this content. Set your block to only display in the content area of this type of page. And then add the page template with header/footer removed and clear the cache.
    – rachel Jun 25 '16 at 03:38

2 Answers2

6

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>');
  }
}
Adam
  • 1,080
  • 1
  • 9
  • 17
1

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.