tags:

views:

60

answers:

2

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! :)

A: 

What do you exactly need to iframe? A node? A block? Should it be static or dynamic?
You can simply create a node with a php filter and generate the iframe output. Then you can put this output between <pre> tags to display it as code that users can copy/paste in their site.

notme
+2  A: 

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

Graham
Graham thanks a lot!
pao13gate
Graham, what you describe works beautifully. Now that we have sorted the rendering of the iframe, any idea on how to make it more efficient - how to bypass preparing elements that are never rendered e.g. the blocks?
pao13gate