Remitur Posted March 19 Share Posted March 19 When you create a client customfield, it's available in .tpl files in two different Smarty variables: - an array like this: customfields => array (18) 0 => array(2) id =>83 value => "mycustomvalue" 1 => array(2) id =>87 value => "mysecondcustomvalue" etc. And a series of useless variables like: customfields1 = "mycustomvalue" customfields2 = "mysecondcustomvalue" This second one is almost useless because there's no safe way to relate each smarty variable to what custom fields; if you create a new custom field the order may change, and you'll have to edit all your custom tpl files... The first one should be more usefull, because the "id" is the same id of the customfield in the tbl customfields in the database So: you create a new client customfield in admin area go to tbl customfields, and recover the id field of the new customfield (i.e. 17) And you should be able to recover its value in tpl, because it will be somewhere in the array "customfields", as "value" element of the sub-array which has id=17 Well, this is the point: how can I recover using Smarty the "value" element of the sub-array with id=17???????????????? 0 Quote Link to comment Share on other sites More sharing options...
Remitur Posted March 19 Author Share Posted March 19 Update: the only way I found to do it is extremely inefficient and almost stupid, through a loop: {foreach from=$customfields item=field} {if $field.id == 17} {$field.value} {/if} {/foreach} Any better idea? 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted March 19 Share Posted March 19 Custom fields are a pain to deal with in WHMCS. Other than placing a {break} if the field is found, there's not really more optimization that can be done - unless you can access it by $customfields.17.value, which I assume you can't. 1 Quote Link to comment Share on other sites More sharing options...
Solution Remitur Posted Monday at 06:32 PM Author Solution Share Posted Monday at 06:32 PM (edited) Thanks to @Mytihost, I found an elegant solution for this issue. The following hook: add_hook('ClientAreaPage', 1, function($vars) { if (!empty($vars['clientsdetails']['customfields'])) { $customfieldsAssoc = []; foreach ($vars['clientsdetails']['customfields'] as $field) { $customfieldsAssoc[$field['id']] = $field['value']; } return ['customfieldsAssoc' => $customfieldsAssoc]; } }); makes available the value of any client custom field in a template, using i.e. the form {$customfieldsAssoc.17} (where "17" is the id field in the tbl customfields) Edited Monday at 06:35 PM by Remitur 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.