ReynierPM ReynierPM - 5 months ago 31
Smarty Question

How to avoid FATAL error in Smarty templates while we check for objects

I am performing the following check in a Smarty template:

{{if $Pricing->getCommission()}}
do something

This is part of the class

class Pricing {
protected $commission;

public function getCommission() {
return $this->commission;

$Pricing = new Pricing();

Then I use the
PHP object in the Smarty template. If
lacks of
property, accessed through
public method this will turn into a FATAL and the application will thrown this to the view or in the best case display a blank page. I want to avoid that, how? I can't change how values are received meaning I can't get rid of the object on the template. Any advice?


Add an isset condition around your statement such as

{{if isset($Pricing->Commission)}} ...

Note that Commission must be a public property. Otherwise you should do as stated in the comment and add a check inside the getCommission method