Michael F Posted December 6, 2015 Share Posted December 6, 2015 Greetings, I'm writing a custom PHP function in the Smarty plugins directory. The problem is that I need to use the $affiliateid variable but it seems that it does not work at all, and not recognized by the function. Does anyone have a clue on how to use or pass a Smarty variable in PHP? Thank you 0 Quote Link to comment Share on other sites More sharing options...
Michael F Posted December 6, 2015 Author Share Posted December 6, 2015 Update: A sample code of what I'm trying to achieve: <?php /* * Smarty plugin * ------------------------------------------------------------- * File: function.* * Type: function * Name: aff * Purpose: outputs a random magic answer * ------------------------------------------------------------- */ function smarty_function_aff($params, &$smarty) { //none of the following display the affiliate id when called in template. print $affiliateid; echo $affiliateid; } ?> And in the template I use {aff} that supposed to display the affiliate ID of the user, however it doesn't display anything, just a blank white area. So my guess is that the PHP function does not recognize the $affiliateid variable. I know I can use {$affiliateid} in the template itself to display the user affiliate ID but I have a different situation. The above code is just a sample. Any suggestions? Thank you in advance 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted December 6, 2015 Share Posted December 6, 2015 what kind of plugin your working on modifier, Prefilter, etc? 0 Quote Link to comment Share on other sites More sharing options...
Michael F Posted December 6, 2015 Author Share Posted December 6, 2015 what kind of plugin your working on modifier, Prefilter, etc? To be honest, I don't have much experience in PHP, so I don't know actually. It's pretty much like the function code I added in my previous reply but with replacing the core code. I need to call that function in the affiliates.tpl file like that {aff}. I'm wondering why is the function not able to read the $affiliateid variable. I'd greatly appreciate it if you could shed some light on this. Thanks 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted December 6, 2015 Share Posted December 6, 2015 if you are writing a smarty function, this is how to pass the variable to it: {functionName affiliateid=$affiliateid} then from inside the function it self you can read it like that: function smarty_function_functionName($params, Smarty_Internal_Template $template) { $affiliateid = $params['affiliateid']; } 0 Quote Link to comment Share on other sites More sharing options...
Michael F Posted December 6, 2015 Author Share Posted December 6, 2015 if you are writing a smarty function, this is how to pass the variable to it: {functionName affiliateid=$affiliateid} then from inside the function it self you can read it like that: function smarty_function_functionName($params, Smarty_Internal_Template $template) { $affiliateid = $params['affiliateid']; } Thank you for the answer, it is greatly appreciated I'm trying to append the affiliate ID to URL. I modified my code to contain what you've mentioned but I couldn't make it work. <?php /* * Smarty plugin * ------------------------------------------------------------- * File: function.* * Type: function * Name: aff * Purpose: outputs a random magic answer * ------------------------------------------------------------- */ function smarty_function_aff($params, &$smarty) { $affiliateid = $params['affiliateid']; $refflink = 'http://example.com/*?aff=' . $affiliateid .''; print $refflink; } ?> Still the $affiliateid doesn't seem to work as if it is not even exists. It prints only the first part of the URL without the affiliate ID, like this: http://example.com/*?aff= What I'm missing here? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted December 6, 2015 Share Posted December 6, 2015 you did this part yet? {aff affiliateid=$affiliateid} you may need to make sure that $affiliateid has a value first! 0 Quote Link to comment Share on other sites More sharing options...
Michael F Posted December 6, 2015 Author Share Posted December 6, 2015 you did this part yet? {aff affiliateid=$affiliateid} you may need to make sure that $affiliateid has a value first! That's my bad Works like charm now Thank you so much for your time and help 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.