0

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";
 
 }
 }
 
}
asked Aug 24, 2020 at 12:31

1 Answer 1

0

$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
2
  • 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 value Commented Aug 24, 2020 at 12:56
  • Have you considered using $this->getLayout() ? Commented Aug 24, 2020 at 13:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.