claudio419 Posted October 21, 2015 Share Posted October 21, 2015 Hi! I need to see one PHP function from one tpl, something like $link works {$link->getPageLink('cart',false, NULL, "add=1&id_product={$product.id_product|intval}&token={$static_token}", false)|escape:'html':'UTF-8') but until now, I couldn't. 1) I was writing : The Function: getCategoryParent() in Product.php public function getCategoryParent(){ return 'Hello from Product.php'; } 2) in product-list.tpl I have: {$product->getCategoryParent()} But I have: Fatal error: Call to a member function getCategoryParent() on array in /Applications/XAMPP/xamppfiles/htdocs/......................./cache/smarty/compile/75/b5/0c/75b50c4c7f0c97cc4699dca3b7bd4363950e5044.file.product-list.tpl.cache.php on line 190 Can someone Help me? Thanks! Link to comment Share on other sites More sharing options...
NemoPS Posted October 21, 2015 Share Posted October 21, 2015 That is because $product in the product list is not an object. You might try using another method like public static function getCategoryParent($id_product){ return 'Hello from Product.php'; } and in the tpl Product::getCategoryParent($product.id_product)But This is not the ideal way I'd go for it Link to comment Share on other sites More sharing options...
claudio419 Posted October 21, 2015 Author Share Posted October 21, 2015 Thanks a lot!!!! Its work Link to comment Share on other sites More sharing options...
alaaghribi Posted November 28, 2016 Share Posted November 28, 2016 That is because $product in the product list is not an object. You might try using another method like public static function getCategoryParent($id_product){ return 'Hello from Product.php'; } and in the tpl Product::getCategoryParent($product.id_product) But This is not the ideal way I'd go for it I know that's an old topic, but I just would like to know why are you saying that it's not the ideal way ? Is there any other better way of calling a php function from a tpl file ? Link to comment Share on other sites More sharing options...
NemoPS Posted November 30, 2016 Share Posted November 30, 2016 Yeah, you should assign the variable from a controller, like ProductController or CategoryController, depending on the page you want to have it for Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now