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";
        
    }

  }
    
}

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 :)

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.