Marcel Wasilewski
Marcel Wasilewski

Reputation: 2679

Pass several variables from Smarty to PHP function

We got a shopsystem working with Smarty. I need to pass some Smarty variables to a PHP function and get the return.

What I know and also did so far is the following:

{$order_id|@get_order_total}

So this passes the Smarty Variable "$order_id" to a included PHP file which contains the function get_order_total($order_id) and shows me the return of this function.

Now I need to pass 3 variables to a PHP function. The function would for example look like this:

handleDebit($order, $payCode, $insertId)

Sadly i have not found the right thing so far in smarty documentation. Anyone has ever done this?

Upvotes: 1

Views: 152

Answers (1)

user594138
user594138

Reputation:

If you really need to call the function from within smarty templates, register a wrapper function as smarty-plugin:

<?php
$smarty->registerPlugin("function","handleDebit", "handleDebitSmarty");

function handleDebitSmarty($params, $smarty)
{
  return handleDebit($params['order'], $params['payCode'], $params['insertId']); 
}

Now you can use it as smarty tag:

{handleDebit order=$blah payCode=$blub insertId=$yeahh}

But you should consider @JonSterling s advice and try to find a way auch that a controller is doing the handleDebit-call and you only handle results/display-stuff in the template.

Upvotes: 1

Related Questions