Here is an example for the travel prices (TV names from german words, comments translated). The snippet call in the travel detail pages template is:
without any parameters because I don’t need them. It collects all necessary information from TVs and returns the formatted result.
This is the snippet:
<?php
$id= (isset($id))? $id : $modx->documentIdentifier;
$pr1 = $modx->getTemplateVar('reisePreis1',"*",$id); // price per passenger
$pr1 = $pr1['value'];
$dz1 = $modx->getTemplateVar('reiseDZ',"*",$id); // if double room = "no" then take text of reiseDZ2 and ignore reiseEZ1
$dz2 = $modx->getTemplateVar('reiseDZ2',"*",$id); // text of reiseDZ2
$ez1 = $modx->getTemplateVar('reiseEZ1',"*",$id); // additional charge for single room, if empty return "no additional charge"
$ez1 = $ez1['value'];
$pa1 = $modx->getTemplateVar('reisePA',"*",$id); // price for 1st passenger in partner campaign
$pa1 = $pa1['value'];
$pa3 = $modx->getTemplateVar('reisePA3',"*",$id); // price for single room in partner campaign
$pa3 = $pa3['value'];
$pri = $modx->getTemplateVar('reisePreisInfo',"*",$id); // additional information to prices like admission fees ...
// common return of prices
if (($pr1 != '') && ($pa1 == '') && ($pa3 == '')) {
$output = '<h2><span>Preise pro Person:</span></h2>';
$output .= '<p>';
$pr1 = str_replace(',-', '', $pr1); $pr1 = str_replace('.-', '', $pr1); $pr1 = str_replace(',--', '', $pr1); $pr1 = str_replace('.--', '', $pr1); trim($pr1);
if (strpos($pr1, '.') > 1) { $pr1 = str_replace('.', ',', $pr1); $output .= $pr1.' €'; } else { $output .= $pr1.',– €'; }
if ($dz1['value'] == 'ja') {
if ($ez1 != '') {
$output .= ' im Doppelzimmer, EZ-Zuschlag: ';
$ez1 = str_replace(',-', '', $ez1); $ez1 = str_replace('.-', '', $ez1); $ez1 = str_replace(',--', '', $ez1); $ez1 = str_replace('.--', '', $ez1); trim($ez1);
if (strpos($ez1, ',') > 1) {
$output .= $ez1.' €.';
}
else {
$output .= $ez1.',– €.';
}
} else {
$output .= ', kein EZ-Zuschlag.';
}
} else {
$dz2 = nl2br($dz2['value']);
$output .= ' '.$dz2;
}
$output .= '</p>';
}
// prices for partner campaign
if (($pr1 != '') && ($pa1 != '') && ($pa3 != '')) {
$output = '<h2><span>Partner-Aktion:</span></h2>';
$pr1 = str_replace(',-', '', $pr1); $pr1 = str_replace('.-', '', $pr1); $pr1 = str_replace(',--', '', $pr1); $pr1 = str_replace('.--', '', $pr1); trim($pr1);
if (strpos($pr1, '.') > 1) { $pr1 = str_replace('.', ',', $pr1); $pr1 = $pr1.' €'; } else { $pr1 = $pr1.',– €'; }
$pa1 = str_replace(',-', '', $pa1); $pa1 = str_replace(',--', '', $pa1); trim($pa1);
if (strpos($pa1, ',') > 1) { $pa1 = $pa1.' €'; } else { $pa1 = $pa1.',– €'; }
$pa3 = str_replace(',-', '', $pa3); $pa3 = str_replace(',--', '', $pa3); trim($pa3);
if (strpos($pa3, ',') > 1) { $pa3 = $pa3.' €'; } else { $pa3 = $pa3.',– €'; }
$output .= '<p>Der 2. Gast im Doppelzimmer bezahlt für diese Reise wirklich <strong>nur '.$pr1.'</strong>. ';
$output .= 'Der 1. Gast im Doppelzimmer bezahlt für diese Reise <strong>nur '.$pa1.'</strong>. ';
$output .= 'Preis im Einzelzimmer: '.$pa3.'.</p>';
}
// return of additional info
if ($pri['value'] != '') {
$output .= $pri['value'];
}
return $output;
?>
All TVs requested are in the same document and are simple text fields. The snippet call is integrated in assigned template. Previewing the document unpublished the place containing the snippet call is empty. I’m not a skilled coder (and I think the code above is horrible for coders in hell

) but I wrote some other individual snippets for clients that work perfect. This works perfect too but only with published documents. And I never found a solution why results are empty on unpublished docs.
Maybe I can’t "getTemplateVar" if unpublished? Works this API function only with published docs?