Hey guys. Before proceeding, I have read
https://vborg.vbsupport.ru/showthread.php?t=228078 and am still not sure what's up with my code.
First, I have this function which is based on a user profile field single select menu.
PHP Code:
function get_ccode ($countryname) {
$json = file_get_contents('http://country.io/names.json');
$countries = json_decode($json, true);
while ($cname = current($countries)) {
if ($cname == $countryname) {
return key($countries);
}
next($countries);
}
}
This and other functions are located in a folder on the server. I have added a plugin at the hook "global_bootstrap_init_start" with this code:
PHP Code:
require(DIR . '/custom/functions.php');
I am now trying to create a code to output a template variable in postbit_legacy. This is the code I have for my plugin which is at the hook "process_templates_complete".
PHP Code:
$country = $user['field58'];
$ccode = get_ccode($country);
if ($ccode != null) {
$imgoutput = "<img src='images/flags/$ccode.png' /> ";
}
$templater = vB_Template::create('countrytemplate');
$templater->register('cimg', $imgoutput);
$templatevalues['ccimg'] = $templater->render();
vB_Template::preRegister('postbit_legacy', $templatevalues);
Then I attempt t use {vb:raw ccimg} in the postbit_legacy template and nothing appears. Where am I going wrong? Thanks in advance.