3

i search around a lot about references of this function. but the documentation have a big lack. does somebody explain me this part of code (deeply) ?

            $this->getLayout()->createBlock(
            ClassElementLikeSelect::class,
            '',
            ['data' => ['is_render_to_js_template' => true]]
            );

i don't understand this solution. i find this everywhere but nobody explain why you set that argument (is_render_to_js_template for example) .

UPDATE:

the createBlock is definite with block Factory and are inside these classes

https://github.com/magento/magento2/blob/0eb8677b0b4e35606032e856cc1ef7c80e68829f/lib/internal/Magento/Framework/View/Layout.php

https://github.com/magento/magento2/blob/0eb8677b0b4e35606032e856cc1ef7c80e68829f/lib/internal/Magento/Framework/View/Layout/Generator/Block.php

1 Answer 1

3

This is only used in a couple of places

https://github.com/magento/magento2/search?q=is_render_to_js_template&unscoped_q=is_render_to_js_template

    /**
     * Block Factory
     *
     * @param string $type
     * @param string $name
     * @param array $arguments
     * @return \Magento\Framework\View\Element\AbstractBlock
     */
    public function createBlock($type, $name = '', array $arguments = [])

So it's arguments that you are passing to block.

As to why. I'm baffled. Other than online tutorials and the two references above I can't find anything.

You can echo out blocks. Sometimes useful for debugging. See if it makes a difference to output?

echo $this->getLayout()
    ->createBlock('Vendor\Extension\Block\Hello')
    ->toHtml();
1
  • thank you man probably i have found the answer i put under the question. but you help me a lot really thanks
    – Pavel
    Jun 14, 2019 at 6:42

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.