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;

  • have you got the solution from my answer? – Chirag Patel May 27 '18 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 '18 at 7:45
  • in cms pages HOME – Altravista May 27 '18 at 11:26
  • Have you got solution? – Chirag Patel Sep 26 '18 at 8:39
2

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.

|improve this answer|||||
  • it does not works for me – Altravista May 27 '18 at 6:28
  • Did you get any error? – Chirag Patel May 27 '18 at 6:29
  • no errros but get no products – Altravista May 27 '18 at 6:33
  • Can you share your code – Chirag Patel May 27 '18 at 6:35
  • this works $productCollection = $productBlock->getProductCollection(array(23)); this does not works $productCollection = $productBlock->getProductCollection(array($block->getData('cat'))); – Altravista May 27 '18 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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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