Hi all,
I have spent the last few days trying to come to terms with this template. I have looked through and played with the given examples, i'm trying to adapt the emailing given example to basically output a word document.
My php code is as follows..
<?php
include_once('tbs_class.php');
include_once('tbs_plugin_opentbs.php');
// prepare template
$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
// data
$data = array();
$data[0] = array('email' =>'bb@bb.com',
'firstname' =>'Brad',
'lastname' =>'bradson',
'receiptno' =>'144543');
$data[0]['products'][] = array('product' =>'Macbook Pro 13" Retina',
'qty' =>1,
'uprice' =>1200.00);
$data[0]['products'][] = array('product' =>'PHP For noobs',
'qty' =>1,
'uprice' =>11.0);
$data[0]['products'][] = array('product' =>'20 Marlboro Gold',
'qty' =>1,
'uprice' =>5.99);
$data[1] = array('email' =>'JS@JS.com',
'firstname' =>'Josh',
'lastname' =>'Smith',
'receiptno' =>'144543');
$data[1]['products'][] = array('product' =>'Meditation for noobs',
'qty' =>1,
'uprice' =>12.00);
$data[1]['products'][] = array('product' =>'JQuery for noobs',
'qty' =>1 ,
'uprice' =>15.0);
$data[1]['products'][] = array('product' =>'Vape',
'qty' =>1,
'uprice' =>69.99);
// Load template
$template = '\email_template.docx';
$TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8); // Also merge some [onload] automatic fields (depends of the type of document).
// Debug
if (isset($_POST['debug']) && ($_POST['debug']=='current')) $TBS->Plugin(OPENTBS_DEBUG_XML_CURRENT, true); // Display the intented XML of the current sub-file, and exit.
if (isset($_POST['debug']) && ($_POST['debug']=='info')) $TBS->Plugin(OPENTBS_DEBUG_INFO, true); // Display information about the document, and exit.
if (isset($_POST['debug']) && ($_POST['debug']=='show')) $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW); // Tells TBS to display information when the document is merged. No exit.
$subject = $TBS->TplVars['subject']; // sets subject variable from template
// merge
foreach ($data as $recipiant)
{
$TBS->MergeField('i', $recipiant);
$TBS->MergeBlock('a', $recipiant['products']);
$TBS->Show(TBS_NOTHING); // merge automatic TBS fields
$body = $TBS->Source;
$txt = 'To: '.$recipiant['email']."\r\n".'Subject: '.$subject."\r\n".$body."\r\n\r\n============================================\r\n\r\n";
$TBS->Source = '<html><head></head><body><div id="main-body"><pre>'.$txt.'</pre></div></body></html>';
$TBS->Show(OPENTBS_DOWNLOAD); // Also merges all [onshow] automatic fields.
// Be sure that no more output is done, otherwise the download file is corrupted with extra data.
}
?>
And my docx template is as follows: |
[onload;tplvars;subject=Hi!;comm=_]
Dear [i.firstname] [i.lastname],
this is your order receipt.
Receipt #[i.receiptno].
~~~~~~~~~~~~~~~ [a.#;block=begin;comm=_] ~~~~~~~~~~~~~~~
Product #[a.#]
----------
Product: [a.product]
Quantity: [a.qty]
Price: £[a.uprice;frm=0.00]
~~~~~~~~~~~~~~~ [a.#;block=end;comm=_] ~~~~~~~~~~~~~~~
Thankyou & Have a nice day [i.firstname]!
www.nonexistentshop.org
As of now, a blank word document is output. Any help would be much appreciated!
Thanks,