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? 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
    May 27, 2018 at 7:45
  • in cms pages HOME
    – Altravista
    May 27, 2018 at 11:26
  • Have you got solution? 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
    May 27, 2018 at 6:28
  • Did you get any error? May 27, 2018 at 6:29
  • no errros but get no products
    – Altravista
    May 27, 2018 at 6:33
  • Can you share your code 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
    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 that you have read and understand our privacy policy and code of conduct.

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