Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an Iframe from a Drupal Website

Tags:

iframe

drupal

I have a drupal website. I want to generate an Iframe with content from my drupal site, that other sites can embed.

How I think this can be achieved:

Method 1: Create a php script that is autonomous from the drupal engine.

Import the configuration file and hence gain access to the database. Generate the content as a standalone webpage. Distribute the url of this script as the iframe's source url. Problems: cannot provide drupal functionality within the iframe such as interaction with logged in user.

Method 2: Create the iframe from within drupal.

Create a new module that defines a menu entry using hoom_menu (the url for the iframe). Define the content of the iframe from the callback function of the menu entry. Then Somehow assign a custom page.tpl.php theme for the desired iframe url so that only the content of the iframe is rendered without all the other page elements (blocks, menus, footer, etc.).

Any comments especially for method 2 will be greatly appreciated! :)

like image 427
sincospi Avatar asked Feb 25 '23 23:02

sincospi


2 Answers

I have done exactly this, just this week!

I created a custom module that outputs only the content that I want (using hook_menu()). Then I created a page template (page-mycustommodule.tpl.php) that only has

<?php print $content; ?> 

within the <body> tags.

That was basically all. To find out the name that your page template needs to have, use the devel and theme_devel modules, then just click on your page and it will tell you which templates it looked for.

One thing to look out for: any links in the iframe will only change the contents OF THAT FRAME, so when your module creates links, use the proper target to make the parent page jump to the new URL:

l('link text',
  'node/' . $mynode->nid,
   array('attributes' => array('target' => '_parent')));
like image 177
Graham Avatar answered Mar 12 '23 06:03

Graham


I found the answer by Graham very useful. Unfortunately I don't have enough reputation on this site to add a comment so I will have to put my comment in an answer.

5 years on, the information has changed slightly:

  • The module theme_devel now seems to be called devel_themer instead.
  • In D7, the template naming pattern is slightly different with 2 hyphens: page--[front|internal/path].tpl.php (see docs)
  • D7 templates are slightly different based on render arrays, so the template will need to be something like print render($page['content']);
like image 41
AdamS Avatar answered Mar 12 '23 05:03

AdamS