在Drupal 9中显示不带页模板的Drupal视图9
我想在我的网站上添加一些链接,这些链接在平原HTML的新标签中打开页面的内容,而没有任何主题等。 起初,我只是在我的node.twig中添加了一个链接,然后尝试使用JavaScript来做这件事,但我没有成功实现它。
当我们默认使用链接时,将应用主题,因此在“新选项”中页面相同。 我搜索了一种方法,找到了这篇文章:
基于Ufonion Labs的答案,我能够完全删除 Drupal 7中页面内容周围的所有HTML输出 实现
hook_preprocess_page
和hook_preprocess_html
in 我的主题template.php,这样:函数my_theme_preprocess_page(& $ variables){ if(isset($ _ get ['response_type']) $变量['theme_hook_suggestions'] [] ='page__embed'; } } 函数my_theme_preprocess_html(& $ variables){ if(isset($ _ get ['response_type']) $变量['theme_hook_suggestions'] [] ='html__embed'; } }
然后,我在主题中添加了两个模板:
html-- embed.tpl.php
:<?php Print $ page; ?>
和
page--embed.tpl.php
:<?php打印渲染($ page ['content']); ?>
现在,当我打开一个节点页面时,例如 http://example.com/node/node/3 ,我明白了 完整的页面照常 参数,例如 http://example.com/node.com/node/node/3?Response_type = embed ,我 仅使用页面内容获取
< div>
,以便可以将其嵌入另一页。
我真的很喜欢URL路径确定输出主题是否已加载,但在我的情况下它不起作用:我在Drupal 9上使用twig进行呈现视图但是,您如何为树枝做零件呢?我想知道您是否认为我可以实现同样的事情,还是不可能这样做。
我的第二个解决方案是执行自定义模块,但我对此不熟悉,因此这就是为什么我估算所有可能的解决方案的原因。
最好的问候,祝您有美好的一天!
I'd like to add in my website some links which open the content of the page in a new tab in plain html without any theme etc.
At first I added just a link in my node.twig and try with Javascript to do the thing but I didn't successfully achieve it.
When we use a link by default the theme is applied and so the page is just the same in the new tab.
I searched a way to do that and I found this post :
displaying a Drupal view without a page template around it
Based on the answer of Ufonion Labs I was able to completely remove
all the HTML output around the page content in Drupal 7 by
implementing bothhook_preprocess_page
andhook_preprocess_html
in
my themes template.php, like this:function MY_THEME_preprocess_page(&$variables) { if (isset($_GET['response_type']) && $_GET['response_type'] == 'embed') { $variables['theme_hook_suggestions'][] = 'page__embed'; } } function MY_THEME_preprocess_html(&$variables) { if (isset($_GET['response_type']) && $_GET['response_type'] == 'embed') { $variables['theme_hook_suggestions'][] = 'html__embed'; } }
Then I added two templates to my theme:
html--embed.tpl.php
:<?php print $page; ?>
and
page--embed.tpl.php
:<?php print render($page['content']); ?>
Now when I open a node page, such as http://example.com/node/3, I see
the complete page as usual, but when I add the response_type
parameter, such as http://example.com/node/3?response_type=embed, I
only get the<div>
with the page contents so it can be embedded in another page.
I really like than the url path determine the output if the theme is loaded or not but in my case it's not working: I'm on Drupal 9 with Twig for rendering view so I added the code of template.php in the .theme file but how do you do the part for Twig ? I wonder if you think I can achieve the same thing or is it not possible to do it that way.
My second solution would be to do a custom module but I'm not familiar with that so that's why I estimate all the possible solution.
Best regards and have a good day !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是您想做的,但是在添加主题建议后,您可以使用自定义模板覆盖页面
模板
在基本主题文件夹主题/模板/布局/中创建模板/
例如
主题/模板/布局/page-- embed.html.twig
如果您希望URL确定模板或主题,则需要编写一个自定义控制器,可以在其中使用自定义模板渲染实体,但也可以这样做在主题中不建议
解决问题的简单方法:
template = them/page/page-embed.html.twig
template = theme/temeplates/layplates/page/page-
embed.html.twig链接具有此查询参数?模板=嵌入末端
eg example.com/node/3?template=
embed url url具有“ template” = emplate emp the末尾,代码应该工作。
替换themename =&gt;带有您的主题名称
I m not sure this is what you want to do but you can override the page template with a custom template after adding a theme suggestion
Then
Create a template in your base theme folder theme/templates/layout/
e.g
theme/templates/layout/page--embed.html.twig
If you want the URL to determine the template or theme then you would need to write a custom controller where you can render entity with a custom template but you can also do it in the theme which is not recommended
Easy way to solve your problem:
Template = theme/templates/layout/page--embed.html.twig
Template = theme/templates/layout/page--embed.html.twig
Make sure all your links have this query parameter ?template=embed at the end
e.g example.com/node/3?template=embed
as long the URL has ?template=embed at the end, the code should work.
replace themename => with your theme name