i’m trying to create a simple snippet that can be called multiple times on a page.
This snippet takes 3 parameters and outputs two placeholders.
Basically, you enter in the original price of an item (p), a sale price (s), and a boolean determining whether or not the item is on sale (c).
I had this working great until I tried to add it to a Ditto call and then realized it was screwing up when it was called multiple times. Now I’m completely lost.
<?php
if(!function_exists(salecost)) {
function salecost($p, $s, $c){
if ($c == '1') {
$cost = '<del>$'.$p.'</del><br /><span style="color:red;">$'.$s.'</span>';
$frmcost = $s;
}else{
$cost = '$'.$p;
$frmcost = $p;
}
$modx->setPlaceholder('cost', $cost);
$modx->setPlaceholder('frmcost', $frmcost);
}
return;
}
?>
Sample of how I’m calling it:
[[salecost? &p=`20` &s=`12` &c=`1` ]]
It just doesn’t produce anything now. Do I need to add a function call within the snippet? How do I execute a snippet wrapped in a function without calling the function?