Hello,
I have a simple snippet that takes three variables. This is for a simple catalog of products. If the variable ’onsale’ is checked, the snippet takes the items price (TV: price), strikes it out and writes the sale price (TV: saleprice).
This snippet works great on the product pages but I wanted to include it in ditto where I have my category landing pages. The template variables needed for the snippet are being read correctly and on their own appear just fine within the ditto call. The snippet placeholder ([+cost+]) is also showing up. The snippet just doesn’t recognize if the onsale variable is checked or not and doesn’t show the sale price if it is. Here’s the snippet code:
<?php
/*
This snippet is used to check whether the 'chksale' template variable
has been checked. It then displays the appropiate price.
This snippet takes 3 parameters
&orprice=`[*price*]` //TV price - Original price of item
&saleprice=`[*saleprice*]` //Sale Price of the item; TV saleprice
&onsale=`[*chksale*]` //TV chksale determines whether it's on sale.
Call:
[!salecost? &orprice=`[*price*]` &saleprice=`[*saleprice*]` &onsale=`[*chksale*]`!]
Produces two placeholders:
[+frmcost+] //Numeric price for PayPal form
[+cost+] //Pre formatted HTML string to strikeout itemprice and display saleprice
Still to come:
Add exception if sale date has expired.
*/
if ($onsale == 1) {
$cost = '<del>$'.$orprice.'</del><br /><span style="color:red;">$'.$saleprice.'</span>';
$frmcost = $saleprice;
}else{
$cost = '$'.$orprice;
$frmcost = $orprice;
}
$modx->setPlaceholder('cost', $cost);
$modx->setPlaceholder('frmcost', $frmcost);
return;
?>
Here’s the Ditto call on the category page:
[!Ditto? &parents=`3` &tpl=`dittoTpl` &tagData=`cats` &tagDelimiter=`,` &tagMode=`onlyTags` &tags=`Widgets`!]
And here’s the snippet call within Ditto template:
[[salecost? &orprice=`[+price+]` &saleprice=`[+saleprice+]` &onsale=`[+chksale+]`]]
I’m not sure why this isn’t working. Right below the salecost call I’m calling Maxigallery which is working great.