souzadavi Posted June 10, 2021 Share Posted June 10, 2021 Hello, my custom email templates not getting custom fields, my variable is set like on: https://docs.whmcs.com/Custom_Fields at email template is show this example: {$service_custom_fields.1} and this one: $service_custom_fields_by_name.0.name}: {$service_custom_fields_by_name.0.value} if my customer field name is cpfnumber how the custom fields should be on email template? Actual is like this: {$service_custom_field_cpfnumber} but not working. Thanks. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted June 10, 2021 Share Posted June 10, 2021 To get service_custom_field_cpfnumber, you would need to go through the service_custom_fields_by_name array, check the name variable and if it is cpfnumber, then show. {foreach from=$service_custom_fields_by_name item=customfield} {if $customfield.name eq 'cpfnumber'} {$customfield.name}: {$customfield.value} {else} {/foreach} The service_custom_fields_by_name array uses numbers for keys and not the custom field name and thus you have to go hunt for it. 1 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 11, 2021 Share Posted June 11, 2021 ... and should only be available to "Product" type email templates. 1 Quote Link to comment Share on other sites More sharing options...
souzadavi Posted June 16, 2021 Author Share Posted June 16, 2021 Thanks guys!!! I just did a little change from the @steven99 code. {foreach from=$service_custom_fields_by_name item=customfield} {if $customfield.name eq 'cpfnumber'} {$customfield.name}: {$customfield.value} {/if} {/foreach} Now is working again!!! 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted June 16, 2021 Share Posted June 16, 2021 Just thought of this and figured I would note just in case. If you need to have the customfield in multiple locations in the message, using smarty's assign would work better than looping each time: {foreach from=$service_custom_fields_by_name item=customfield} {if $customfield.name eq 'cpfnumber'} {assgin cpfnumber=$customfield.value} {/if} {if $customfield.name eq 'some_other_field'} {assgin otherfield=$customfield.value} {/if} {/foreach} ...... else where in the message CPF #: {$cpfnumber} 1 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 17, 2021 Share Posted June 17, 2021 On 10/06/2021 at 19:26, souzadavi said: if my customer field name is cpfnumber how the custom fields should be on email template? Actual is like this: {$service_custom_field_cpfnumber} but not working. if the field is called cpfnumber, and it's a product type email template, then {$service_custom_field_cpfnumber} should work... just tried it on a product custom email (in v8.1.3), and the service fields were there - both individually and in the array.... obviously, if the value is empty, then it effectively returns nothing (though you should get the same result by looping through the array). worst case, remember that this is a Smarty template, so you can add {debug} to the template and when you send a test message using that template, and then view the email in the admin area, it should open up the usual debug window and allow you to see some of the variables available, e.g your service custom fields.... remove it again from the template when you're finished. 17 hours ago, steven99 said: Just thought of this and figured I would note just in case. If you need to have the customfield in multiple locations in the message, using smarty's assign would work better than looping each time: remembering to spell assign correctly too would help. 😲 for the record, I tried your code and it threw up multiple Smarty errors.. fixed by using.. {foreach from=$service_custom_fields_by_name item=customfield} {if $customfield.name eq 'cpfnumber'} {assign "cpfnumber" $customfield.value} {/if} {/foreach} though unless you're using a version that was bugged in this respect, this should be unnecessary. 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.