1

I am accessing block function in phtml like

$blockObj= $block->getLayout()->createBlock('Esparksinc\Extension\Block\Product\View');

but this gave Waring of class notation instead while cheqing code during coding standarded.

2 Answers 2

6

Use

$blockObj= $block->getLayout()->createBlock(\Esparksinc\Extension\Block\Product\View::class);

instead of

$blockObj= $block->getLayout()->createBlock('Esparksinc\Extension\Block\Product\View');

Or, Add this block using layout.

5
  • I want to do it in .phtml file. Any idea? Commented Dec 18, 2019 at 13:21
  • Its works for phtml file as well. Commented Jan 9, 2020 at 10:12
  • It should be withing Quotation '\Esparksinc\Extension\Block\Product\View:class' Commented Feb 20, 2020 at 11:21
  • it should be \Esparksinc\Extension\Block\Product\View::class .Double :: Commented Feb 20, 2020 at 11:45
  • Not required single quote ()` Commented Feb 20, 2020 at 11:45
0

Bacically block is attached with its phtml so we can directly call block function from phtml so there is no need to create the block object at all like.

$block->callBlockFunction();

Your Answer

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.