1

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?

1
  • 1
    Question. Why are you doing this from smarty at all and not dealing with it in your controller (or whatever you're using)? Commented Nov 18, 2015 at 10:39

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.