Jump to content

Call PHP Function from tpl


claudio419

Recommended Posts

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

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

  • 1 year later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...