Forum Discussion

wilderichsophus's avatar
9 years ago

Email Template - Getting User First Name From the Input

Hi Lithium Community,

 

A quick enquiry, we are currently trying to update the default user registration email template with a custom HTML template.

 

We are stuck at trying to find a way to pull-in user submitted First name field.

$user.first_name and $first_name doesn't seem to work.

 

Any suggestion would be highly appreciated.

 

Thank you.

  • wilderichsophus,

     

    Welcome to the Lithium Community. I'm sure you'll find this a very useful place.

     

    I'm not sure if you can achieve what you want to do, but I would guess that the vast majority of communities would use $user.login (username) as that's what community members are generally going to be referred to on the community - that's their chosen "name".

     

    Also, have you made completing the first name field when registering mandatory for community members? If not then obviously using the first name might not be a great idea for the notification.

     

    Jason

    • wilderichsophus's avatar
      wilderichsophus
      Adept
      Hi Jason,

      Yes, I can pull in username using $user.login, though I was thinking for a bit more personalised greetings using first name - "Hi, John!"

      Yes, I have also made the first name field mandatory for this purpose.

      Thank you for the input, Jason.

      Regards,
      Johan
  • wilderichsophus if this is possible to call api from your context, you could easily get user first_name and last_name.

    <#assign apiVersion = "2.0"/>
    <#assign user_id = 'user-id'>
    <#assign userQuery = "select first_name,last_name from users where id = '${user_id}' "/>
    <#assign usersData = rest(apiVersion, "/search?q=" + userQuery?url).data.items[0]/>
    ${usersData.first_name}
    ${usersData.last_name}

    Give Kudo if you find my post helpful.

    • wilderichsophus's avatar
      wilderichsophus
      Adept
      Hi tariq,

      I apologise for the late reply.

      I have been turning your recommended snippet upside down. I am afraid the HTML email template that sits inside Studio -> Text Editor -> Email Text does not execute API call.

      I am still researching for answer.

      Thank you.
    • irach15's avatar
      irach15
      Maven

      TariqHussain,

      was you able to run your code in email template?

      Just looking at the reply bellow about not possible to use API calls in email templates.

      Alos, I believe first name and last name can be only vissible at Admin level...

      Let us know.

      Thank you.