Is it possible to call getdata() from inside the block class like this? Because as it is now, i get no data from getdata().
class Index extends Template implements BlockInterface
{
protected $_template = "";
public function __construct(Template\Context $context, array $data = [])
{
parent::__construct($context, $data);
if($this->getData('template_layout') == "LPS" )
{
$this->_template = "widget/Image_left.phtml";
}else if($this->getData('template_layout') == "RPS")
{
$this->_template = "widget/Image_right.phtml";
}
else if($this->getData('template_layout') == "RPWS")
{
$this->_template = "widget/Image_right_No_Space.phtml";
}
else if($this->getData('template_layout') == "LPWS")
{
$this->_template = "widget/Image_right_No_Space.phtml";
}else{
$this->_template = "widget/Image_right.phtml";
}
}
}
1 Answer 1
$this->getData('test') is only a shortcut for $this->test So if your getData returns null it's because your this object do not have the property you are looking for I guess.
May be you can provide more context. Also with this kind of condition consider using a switch case :)
answered Aug 24, 2020 at 12:42
Clong
1,3441 gold badge13 silver badges32 bronze badges
-
I just want to get the value of template_layout, so i can switch between templates. I get the value from my widget.xml. Everything works, but the only thing i cant seem to do is to access the "template_layout" to get the valueDriton– Driton2020年08月24日 12:56:49 +00:00Commented Aug 24, 2020 at 12:56
-
Have you considered using
$this->getLayout()?Clong– Clong2020年08月24日 13:03:09 +00:00Commented Aug 24, 2020 at 13:03
default