Drupal 8 获取内容并在没有页眉/页脚的情况下提供服务 [英] Drupal 8 fetch content and serve without header/footer
问题描述
我正在开发一个 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 对象.这将只输出您提供的 HTML.
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 SymfonyComponentHttpFoundationResponse;
Class YourController extends ControllerBase {
public function pageFunction() {
return new Response('<html><div>test</div></html>');
}
}
这篇关于Drupal 8 获取内容并在没有页眉/页脚的情况下提供服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!