Variables in PDF template Header and Footer

mediaateam

Administrator
I have a custom PDF template with a header and footer. If I place the divs in the place in the wiki (after: defined('_JEXEC') or die('Restricted access'); and before $form = $this->form;, they work fine, repeating on every page. But, I have a few variables that I would like call into the header, but they aren't assigned until after, so I moved them above the header footer divs, and then I get them in the header on the first page, but the headers and footers do not show up on any other pages.

Here's my code that repeats headers and footers, but doesn't show variable information:

Code:
defined('_JEXEC') or die('Restricted access');
 
 
?>
<div id="footdompdf">
    <span class="footleft">Academy 2015/2016</span>
        <span class="pagenum">Page </span>
</div>
<div id="headerdompdf">
    <span class="headleft">RELEASE PACKET FOR <?php echo $sName; ?> (AppID-<?php echo $sAppID; ?>)</span>
    <span class="pdfdate"><?php echo $rpDate; ?></span>
</div>
<?php
 
$form = $this->form;
$model = $this->getModel();
 
echo $form->intro;
echo '<div class="fabrikForm fabrikDetails" id="' . $form->formid . '">';
echo $this->plugintop;
echo $this->loadTemplate('buttons');
echo $this->loadTemplate('relateddata');
 
$app1Info = $this->groups['Release Packets'];
$app1Keys = $app1Info->elements;
 
$sName = $app1Keys['app_id']->element;
$sAppID = $app1Keys['app_id']->element_raw;
$rpDate = $app1Keys['date_time']->element_raw;

And here's my code that shows the variables, but only has headers and footers on the first page of the pdf:

Code:
defined('_JEXEC') or die('Restricted access');
 
$form = $this->form;
$model = $this->getModel();
 
echo $form->intro;
echo '<div class="fabrikForm fabrikDetails" id="' . $form->formid . '">';
echo $this->plugintop;
echo $this->loadTemplate('buttons');
echo $this->loadTemplate('relateddata');
 
$app1Info = $this->groups['Release Packets'];
$app1Keys = $app1Info->elements;
 
$sName = $app1Keys['app_id']->element;
$sAppID = $app1Keys['app_id']->element_raw;
$rpDate = $app1Keys['date_time']->element_raw;
 
?>
<div id="footdompdf">
    <span class="footleft">Academy 2015/2016</span>
        <span class="pagenum">Page </span>
</div>
<div id="headerdompdf">
    <span class="headleft">RELEASE PACKET FOR <?php echo $sName; ?> (AppID-<?php echo $sAppID; ?>)</span>
    <span class="pdfdate"><?php echo $rpDate; ?></span>
</div>
<?php

Any ideas?
 
You have to set the variables before you use them, in your code example1 you are doing it afterwards (so php will echo empty ones).
 
You have to set the variables before you use them, in your code example1 you are doing it afterwards (so php will echo empty ones).

I tried that in the second code example, but then I only get a header and footer on the first page of the pdf.
 
In your 2nd example you are displaying the dompdfheader/footer divs inside the form's div.
Take you first code but move the variable definitions.
 
AH! I see what you're saying now. Worked like a charm! So the key is that the header/footers need to be OUTSIDE the form's div. For some reason, I was thinking you needed the $form and $model declared before you started assigning any other variables, luckily I was was wrong, lol.
Thanks troester!

Here's my final code in case any one else uses the thread:
Code:
defined('_JEXEC') or die('Restricted access');
 
$app1Info = $this->groups['Release Packets'];
$app1Keys = $app1Info->elements;
 
$sName = $app1Keys['app_id']->element;
$sAppID = $app1Keys['app_id']->element_raw;
$rpDate = $app1Keys['date_time']->element_raw;
 
?>
<div id="footdompdf">
    <span class="footleft">Academy 2015/2016</span>
        <span class="pagenum">Page </span>
</div>
<div id="headerdompdf">
    <span class="headleft">RELEASE PACKET FOR <?php echo $sName; ?> (AppID-<?php echo $sAppID; ?>)</span>
    <span class="pdfdate"><?php echo $rpDate; ?></span>
</div>
<?php
 
$form = $this->form;
$model = $this->getModel();
 
echo $form->intro;
echo '<div class="fabrikForm fabrikDetails" id="' . $form->formid . '">';
echo $this->plugintop;
echo $this->loadTemplate('buttons');
echo $this->loadTemplate('relateddata');
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top