I have created a ViewModel, when I am calling it in the phtml it giving me the below error Fatal error: Uncaught Error: Call to a member function getSomething() on null in Magento_Catalog/templates/product/list/items.phtml:16 Stack trace: #0
here is my catalog_product_view.xml
<block name="product.info.upsell.customviewmodel"
class="Magento\Framework\View\Element\Template"
template="Magento_Catalog::product/list/items.phtml">
<arguments>
<argument name="view_model" xsi:type="object">Noshad\VMpractice\ViewModel\PreparePostData</argument>
</arguments>
</block>
here is my ViewModel class
<?php
namespace Noshad\VMpractice\ViewModel;
use Magento\Framework\View\Element\Block\ArgumentInterface;
class PreparePostData implements ArgumentInterface
{
public function getSomething()
{
echo 'find me';
}
}
here are my items.phtml code
/* @var Noshad\VMpractice\ViewModel\PreparePostData $viewModel */
$viewModel = $block->getData('view_model');
echo $viewModel->getSomething();
whenever I load the product detail page I gets the below error: Fatal error: Uncaught Error: Call to a member function getSomething() on null in /var/www/html/practice234/app/design/frontend/Smartwave/porto_child/Magento_Catalog/templates/product/list/items.phtml:16 Stack trace: #0