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