SagePay iFrame Theme Integration I am using the SagePay Integration Module.  I have created template file for the cart summary / overview (page--cart.tpl).  I have also crated hooks to alter forms on the next two pages mytheme_form_commerce_checkout_form_checkout_alter and mytheme_form_commerce_checkout_form_review_alter and configured template files for them using the mytheme_theme hook.  The templates are commerce-checkout-form-review.tpl.php and commerce-checkout-form-checkout.tpl.php.  

Next I created a template file for the payment page, page--checkout--payment.tpl.php.

SagePay is configured to (only) use Sage Pay Server Integration - specifically Display payment form in an iFrame (can be found at /admin/commerce/config/sagepay).

After investigating the $page variable using Deval/kpr I decided to render 

$page ['content']['content']['content']['system_main']


Here is a copy of the code in the template file (page--checkout--payment.tpl.php).

&lt;?php if (isset($page['header'])) {?&gt;
  &lt;?php print render($page['header']); ?&gt;
&lt;?php }?&gt;

&lt;?php kpr ($page); ?&gt;

&lt;div class="content checkOutForm"&gt;
  &lt;h2&gt;PROCESS PAYMENT&lt;/h2&gt;

  &lt;table width="100%" border="0" cellspacing="5" cellpadding="5"&gt;
    &lt;tbody style="color:#000;"&gt;
    &lt;tr style="color:#000;line-height: 40px;"&gt;
          &lt;th width="20%" align="center"&gt;YOUR BASKET&lt;/th&gt;
          &lt;th width="20%" align="center"&gt;BILLING DETAILS&lt;/th&gt;
          &lt;th width="20%" align="center"&gt;PAYMENT OPTION&lt;/th&gt;
          &lt;th width="20%" align="center"&gt;&lt;strong&gt;PROCESS PAYMENT&lt;/strong&gt;&lt;/th&gt;
          &lt;th width="20%" align="center"&gt;CONFIRMATION&lt;/th&gt;
    &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

&lt;p&gt;&lt;/p&gt;

&lt;?php print render($page ['content']['content']['content']['system_main']); ?&gt;

&lt;/div&gt;

&lt;?php if (isset($page['footer'])) {?&gt;
  &lt;?php print render($page['footer']); ?&gt;
&lt;?php } ?&gt;


The problem is this.  The line 

&lt;?php print render($page ['content']['content']['content']['system_main']); ?&gt;


renders the iFrame, but once that is done, the rest of the page does not get rendered.  So the last part which needs to render the page[footer] is not executed.

I tried to save a copy of page[footer] at the beginning of the file, and then render this copy, but same result - footer does not get rendered.

I am assuming either the $page variable is lost / corrupted during the iframe render (unlikely), or the code stops executing after the iframe is rendered and we never get to the footer part (probably - but not sure why).

If I remove the line to render the iFrame, then footer prints out just fine.

My question is this - how I can render the SagePay iFrame form (in an iFrame) ensuring all relevant form fields (hidden, links, etc) is rendered correctly, and still render this inside one of my template files.
So I had a couple of people asking about this here and on drupal.org - so I figured it would be easier to just tell you what I did.

in commerce_sagepay/inc/commerce_sagepay_server.inc around line 120 there is a piece of code that reads:

  '#markup' =&gt; '&lt;iframe style="width: 600px; height:500px" scrolling="no" frameborder="0" name="iframe_sagepay" id="iframe_sagepay" src="' . url('commerce_sagepay/sagepay_waiting_page') . '" /&gt;',


I changed this line to 

  '#markup' =&gt; '&lt;iframe style="width: 600px; height:500px" scrolling="no" frameborder="0" name="iframe_sagepay" id="iframe_sagepay" src="' . url('commerce_sagepay/sagepay_waiting_page') . '"&gt;&lt;/iframe&gt;',


in other words - explicit close the iframe tag.  It solved the problem for me.  

Hope this helps someone.