smarty - Simplify PHP multiply if conditions -
smarty - Simplify PHP multiply if conditions -
i wonder there way create code more subtle?
ex
public function hookdisplayheader() { if(tools::getvalue('controller')=='index'){ $this->context->controller->addcss(($this->_path).'something.css', 'all'); } if(tools::getvalue('controller')=='cms'){ $this->context->controller->addcss(($this->_path).'something.css', 'all'); } if(tools::getvalue('controller')=='product'){ $this->context->controller->addcss(($this->_path).'something.css', 'all'); } if(tools::getvalue('controller')=='category'){ $this->context->controller->addcss(($this->_path).'something.css', 'all'); } }
to simple
public function hookdisplayheader() { if(tools::getvalue('controller')=='index , product , cms , category'){ $this->context->controller->addcss(($this->_path).'something.css', 'all'); } }
this code not work :(
use in_array();
public function hookdisplayheader() { $values = array('index','cms','product','category'); if(in_array(tools::getvalue('controller'), $values)){ $this->context->controller->addcss(($this->_path).'something.css', 'all'); } }
php smarty prestashop
Comments
Post a Comment