WHMCS Developer WHMCS Andrew Posted January 29, 2008 WHMCS Developer Share Posted January 29, 2008 Hey, I am trying to include a file in my tpl file and pass a smarty variable in to it. -- What I am trying to do, is get the monetary amount from the fields displayed and show a conversion to USD based on a rate set in the database. -- This is what I have so far. {assign var='t1' value=$total|replace:$currency:''} //This replaces the currency words with nothing {assign var='t2' value=$t1|replace:$currencysymbol:''} // this replaces the symbol with nothing //Now the hard part: {include_php file="/home/xxxxx/public_html/billing/includes/conv.php"} //<-- This works but does not calculate anything as I am not passing anything through {include_php file="/home/xxxxx/public_html/billing/includes/conv.php?amount=`$t2`"} \\<== This doesn't work. Anyone any ideas how I can sort this? Not really used to the smarty templating system yet. (And I have tried the smarty manual which doesn't really help a newbie to smarty) 0 Quote Link to comment Share on other sites More sharing options...
AceGX Posted January 29, 2008 Share Posted January 29, 2008 Try {php} include("yourfile.php"); {/php} and place it towards the top of your template file before your {assign} tags. I have always found the {include_php} tag a bit sketchy. 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Developer WHMCS Andrew Posted January 29, 2008 Author WHMCS Developer Share Posted January 29, 2008 but how do I get the t2 varable to reference correctly in the include bit? 0 Quote Link to comment Share on other sites More sharing options...
allynne Posted January 29, 2008 Share Posted January 29, 2008 Not sure if this will work, but have you tried {include_php file="/home/xxxxx/public_html/billing/includes/conv.php?amount=".$t2} 0 Quote Link to comment Share on other sites More sharing options...
allynne Posted January 29, 2008 Share Posted January 29, 2008 You could also check out http://www.phpfreaks.com/smarty_manual/page/language.function.include.php.html {include_php} tags are used to include a php script in your template. If security is enabled, then the php script must be located in the $trusted_dir path. The {include_php} tag must have the attribute "file", which contains the path to the included php file, either relative to $trusted_dir, or an absolute path. By default, php files are only included once even if called multiple times in the template. You can specify that it should be included every time with the once attribute. Setting once to false will include the php script each time it is included in the template. You can optionally pass the assign attribute, which will specify a template variable name that the output of {include_php} will be assigned to instead of displayed. The smarty object is available as $this within the PHP script that you include. which means that the variable would not need to be passed as a $_GET but as $this->t2 ... I'm assuming you can edit the conv.php file? 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Developer WHMCS Andrew Posted January 29, 2008 Author WHMCS Developer Share Posted January 29, 2008 Hi All, the phpfreaks bit is the same manual as the smarty one. I'm really lost now. Trying everything listed in the manual.. and it's not working.. OK, file: function.conv.php put in the "/whmcs/libs/" directory. I'm not too sure on the DB stuff, so if anyone can lend a helping hand <?php // setup our function for fetching stock data function fetch_amount($amount) { // put logic here that fetches $ticker_info // from some ticker resource $db = new Db(); $db->query('select Rate from tblCurrency where Currency = 'USD' LIMIT 1'); $ticker_info = $db->getRows(); $ticker_info *= $amount; return $ticker_info; } function smarty_function_conv($params, &$smarty) { // call the function $ticker_info = fetch_amount($params['amount']); // assign template variable $smarty->assign($params['assign'], $ticker_info); } then in the template (reading the manual.. I'm assuming this should work) {conv amount=`$t2` assign="convert"} I have tried the $t2 with and without the ` marks and the page just comes up white. Can anyone suggest any code changes for my function file? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.