Pradeep, I don't believe that the template filter system and the {{if}}
directive supports operators (==
). If you consult the class, Varien_Filter_Template
, you would find that the ifDirective
parser does not look for expression evaluation in the way you would expect.
Specifically, line 248
calls $this->_getVariable
, which according to your directive is receiving order_date = '03/06/2017'
as the $value
argument, which cannot match any values stored in the filter processor.
The _getVariable
method supports only a few types of values/operations:
- Direct variable name; eg:
order_data
Varien_Object
instances; eg: getOrderData()
- Other objects with a corresponding method name; eg:
order_data()
Another way to solve this problem is to supply a model/object in your conditional, like the order model, with a custom extending method, which you can call to to evaluate the expression outside of the filter processor, like this:
class Your_Module_Model_Order extends Mage_Sales_Model_Order
{
public function checkOrderDate($input)
{
return $this->getData('order_date') == $input;
}
}
And then in your content, rewrite the directive like so:
{{if order.checkOrderDate('03/06/2017') }}
...
Here's a complete working test case:
require_once '/vagrant/public_html/app/Mage.php';
Mage::app();
class MockOrderClass extends Varien_Object
{
public $order_date = '03/06/2017';
public function checkOrderDate($input)
{
return $this->order_date == $input;
}
}
$filter = new Varien_Filter_Template();
$filter->setVariables(array('order' => new MockOrderClass()));
$input = <<<EOF
{{if order.checkOrderDate('03/06/2017') }}
<td style='width: 15%;'>
<span style='font-weight:bold; padding:5px; display:block; background:#e5e5e5;'>Tax(VAT/CST)</span>
</td>
{{else}}
<td style='width: 15%;'>
<span style='font-weight:bold; padding:5px; display:block; background:#e5e5e5;'>Tax(GST)</span>
</td>
{{/if}}
EOF;
echo '<pre>' . (htmlentities($filter->filter($input))) . '</pre>';