jarod Posted July 13, 2017 Share Posted July 13, 2017 I'm trying to add custom field values to the client summary client information in cliensummary.tpl but the only way I can get this to work using what I've found is by assigning the sortorder which doesn't seem very intuitive. <tr><td>Secondary Phone</td><td>{$clientsdetails.customfields1}</td></tr> How can I get the custom field value based on ID rather than sortorder? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 13, 2017 Share Posted July 13, 2017 I'm trying to add custom field values to the client summary client information in cliensummary.tpl but the only way I can get this to work using what I've found is by assigning the sortorder which doesn't seem very intuitive. surely it's intuitive in the sense that you can control the sort order! How can I get the custom field value based on ID rather than sortorder? any number of ways - depending on your coding experience... 1. you could re-sort the array in PHP... via a hook I suppose... might only be a couple of lines... 2. you could re-sort the array using Smarty in the template via the sortby plugin i've previously posted... basically using a foreach loop and specifying the order within the foreach. 3. you could use a hook to query the db or class method to create multiple new variables... e.g $secondaryphone and link it to a specific cf value etc 4. you could use a hook to query the database and get the cf values in a new array sorted however you want... with labels! they're just the four that spring to mind off-hand... 2 is easy, but possibly not practical for this as you don't have labels in the array... 3 would be a safe solution and future proofed... but frankly if it were me, i'd just use customfields1 etc and make a mental note that if you ever add a new ccf into the middle of the sorted order, it's going to mess up the variables you're using. 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted July 13, 2017 Author Share Posted July 13, 2017 Thank you for the info. Is there really no easier way to output the customfields data? I would imagine there be some way to simply output the value of a custom field based on the id... The sort order isn't even really in question except that it is the only way I have found to retrieve the custom field. But yes, is there any way to get the custom field by it's inherit id and display that in the clientsuummary.tpl? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 14, 2017 Share Posted July 14, 2017 Thank you for the info. Is there really no easier way to output the customfields data? the above four options are easy - though perhaps some more than others! I would imagine there be some way to simply output the value of a custom field based on the id... The sort order isn't even really in question except that it is the only way I have found to retrieve the custom field. imagination is good... reality is another matter. by default, you can only work with what's available to you... so in clientsummary.tpl, you'll only have two immediate options... direct access to specific customfield values ($clientsdetails.customfields1}, or an array that includes an ID value and so can be re-sorted by it. as I said last night, outputting via a foreach in the template is easy - but borderline useless in this case because you can't display the name of the customfield (they're not available to the template), so there's no simple way to distinguish them... {foreach from=$clientsdetails.customfields item=customfield} <tr><td>{$customfield.id}</td><td>{$customfield.value}</td></tr> {/foreach} you could use the sortby plugin to sort the customfields array by ID, but you'd still have no labels.. {foreach from=$clientsdetails.customfields|@sortby:id item=customfield} <tr><td>{$customfield.id}</td><td>{$customfield.value}</td></tr> {/foreach} But yes, is there any way to get the custom field by it's inherit id and display that in the clientsummary.tpl? if you don't want the additional code of querying the database or using the class method in a hook, the absolute simplest way I can think to do this in the template is by assigning the customfield names/labels to a new Smarty array and outputting them in the loop... {$cflabels = ['5'=>'Dashboard','6'=>'Where did you hear about us?','7'=>'Other','9'=>'Are you sure?']} {foreach from=$clientsdetails.customfields|@sortby:id item=customfield} <tr><td>{$cflabels.{$customfield.id}}</td><td>{$customfield.value}</td></tr> {/foreach} the above is written for v7.2.2 using Smarty3, but it should work in earlier WHMCS versions (v6 & before) using Smarty2 - though you'd possibly have to use the longer method of assigning a Smarty array. 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted July 14, 2017 Author Share Posted July 14, 2017 Hrm... The last two code examples do not work. I get a partially rendered page without any error info. Running 7.2.2 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 14, 2017 Share Posted July 14, 2017 Hrm... The last two code examples do not work. I get a partially rendered page without any error info. Running 7.2.2 err... methinks you haven't installed the Smarty sortby plugin ? 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted July 14, 2017 Author Share Posted July 14, 2017 You are correct! Once I followed your instructions for creating the smarty plugin the code worked perfect!!! Thank you! 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.