Creating an iframe from a Drupal site

I have a drupal site. I want to create an iframe with content from my drupal site that other sites can embed.

I think this can be achieved:

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

Import the configuration file and therefore gain access to the database. Create content as a separate web page. Distribute the URL of this script as the iframe source url. Problems: I can not provide drupal functionality in an iframe, for example, interaction with a registered user.

Method 2 Create an iframe from inside drupal.

Create a new module that defines the menu entry using hoom_menu (url for iframe). Define the contents of the iframe from the callback function in the menu entry. Then somehow assign a custom theme page.tpl.php to the desired iframe URL so that only the contents of the iframe are displayed without any other page elements (blocks, menus, footer, etc.).

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

+4
source share
4 answers

I did just that, this week only!

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

 <?php print $content; ?> 

in the <body> tags.

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

One thing you need to pay attention to: any links in the iframe will only change the contents of this frame, so when your module creates links, use the right target to make the parent page jump to the new URL:

 l('link text', 'node/' . $mynode->nid, array('attributes' => array('target' => '_parent'))); 
+6
source

I found Graham's answer very helpful. Unfortunately, I do not have enough reputation on this site to add a comment, so I will need to leave a comment in the answer.

After 5 years, the information has changed a bit:

  • Now the theme_devel module is now called devel_themer.
  • In D7, the template naming pattern is slightly different from 2 hyphens: page - [front | internal / path] .tpl.php ( see documents )
  • D7 templates are slightly different from rendering arrays, so the template should be something like print render($page['content']);
+1
source

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

0
source

method 3

you can use this module https://www.drupal.org/project/entity_iframe , which allows you to create IFRAME READY web pages

install it and go to the display settings for your type of content that you want to use as content iframe admin/structure/types/manage/CONTENTTYPE/display

select the IFRAME view and select the fields you want to display

and then use a url like this domain.com/entity_iframe/node/NID and you will have a display without additional footers, etc ...

By default, an EMBED / IFRAME sample is provided to the administrator under each node settings.

  <iframe width="100%" height="300" src="domain.com/entity_iframe/node/96" frameborder="0" class="entity_iframe entity_iframe_node" id="entity_iframe_node_96" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe> 

Settings in admin/config/system/entity_iframe control some details of the embed code

For full control of the theme used, you can use in combination with https://www.drupal.org/project/entity_iframe_theme

0
source

All Articles