2

How can i get this "cat" parameter from my cms page block

{{block class="Magento\Framework\View\Element\Template" template="Altravista_Carousel::product/carousel.phtml" cat="3"}}

in my Block Class?

Altravista\Carousel\Block\Product.php;

4
  • have you got the solution from my answer? Commented May 27, 2018 at 6:10
  • Have you add this {{block class="Magento\Framework\View\Element\Template" template="Altravista_Carousel::product/carousel.phtml" cat="3"}} code in CMS > Page OR CMS > Block?
    – kunj
    Commented May 27, 2018 at 7:45
  • in cms pages HOME
    – Altravista
    Commented May 27, 2018 at 11:26
  • Have you got solution? Commented Sep 26, 2018 at 8:39

2 Answers 2

3

You can use in like this

{{block class="Magento\Framework\View\Element\Template" template="Altravista_Carousel::product/carousel.phtml" cat="3"}}

Now you can get the data by calling:

$myVar = $block->getData('cat');

OR

$myVar = $block->getMyCat();

Note : You should use $block.

10
  • it does not works for me
    – Altravista
    Commented May 27, 2018 at 6:28
  • Did you get any error? Commented May 27, 2018 at 6:29
  • no errros but get no products
    – Altravista
    Commented May 27, 2018 at 6:33
  • Can you share your code Commented May 27, 2018 at 6:35
  • this works $productCollection = $productBlock->getProductCollection(array(23)); this does not works $productCollection = $productBlock->getProductCollection(array($block->getData('cat')));
    – Altravista
    Commented May 27, 2018 at 6:37
0

If you want to access the parameter in your block class, you should use something like this.

{{block class="Altravista\Carousel\Block\Product" template="Altravista_Carousel::product/carousel.phtml" cat="3"}}

Where Altravista\Carousel\Block\Product extends Magento\Framework\View\Element\Template.

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.