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 both
hook_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 !