Jump to content

custom fields not working


Recommended Posts

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.

 

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated