Yeah! I used the NewsListing snippet as a template for how to use placeholders so the user of ShopCart can use a chunk with placeholders for a template!
My form returns these values:
if(isset($_POST['add'])) {
$id = $_POST['id'];
$name = $_POST['name'];
$alias = $_POST['alias'].$modx->config['friendly_url_suffix'];
$quantity = $_POST['quantity'];
$price = ereg_replace("[^0-9.]","",$_POST['price']);
$total = $price * $quantity;
So I set these placeholders:
// set placeholder values
$modx->setPlaceholder('id', $id);
$modx->setPlaceholder('name', $name);
$modx->setPlaceholder('alias', $alias);
$modx->setPlaceholder('quantity', $quantity);
$modx->setPlaceholder('price', number_format($price,2,'.',','));
$modx->setPlaceholder('total', number_format($total,2,'.',','));
// generate the template's output
$cart .= $modx->mergePlaceholderContent($modx->mergeChunkContent($tpl));
And have this as the default template:
$tpl = isset($tpl) ? $modx->getChunk($tpl) :'
<table cellpadding="0" cellspacing="0"><tr>
<td><a href="[+alias+]">[+name+]</a></td>
<td>([+quantity+])</td>
<td class="right">$[+price+]</td>
</tr><tr id="totalcol">
<td colspan="2" class="right">Total:</td>
<td class="right">$[+total+]</td>
</tr></table>';
Don’t want a $ as your currency symbol? Then just set a different template in the snippet arguments, and create a chunk with a different currency symbol. (I know, this is only part of the whole locale business, but at least it’s a start!)
Works great! And my snippet code is getting cleaner and cleaner, and more and more flexible!