CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Use Nick Name instead of First Name as Display Name?
Pages: [1]

Author Topic: Use Nick Name instead of First Name as Display Name?  (Read 494 times)

jkounis

  • I’m new here
  • *
  • Posts: 14
  • Karma: 0
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.20
  • MySQL version: 5.1
  • PHP version: 5.3
Use Nick Name instead of First Name as Display Name?
February 08, 2011, 12:21:42 am
I wonder if the display name has the same Smarty capability as message templates. I would like to use the Nick Name if it exists. Otherwise, I'd like to use the First Name. I tried setting display name to the following, but it doesn't work:

Code: [Select]
{contact.individual_prefix}{ }
{if isset({contact.nick_name}) }
  {contact.nick_name}
{else}
  {contact.first_name}
{/if}
{ }{contact.middle_name}{ }{contact.last_name}{ }{contact.individual_suffix}

My desired output would be "Bill Smith", but the code above results in "Bill William Smith" if nick name="Bill" and first name="William".
is if...then...else a capability of "display name", or is there another way to achieve what I am trying to do?

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Use Nick Name instead of First Name as Display Name?
February 08, 2011, 06:11:17 am
Your basic logic should work--I think it may just be a syntax error. The correct if line may be:

{if isset(contact.nick_name) }

Can you try that?
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

jkounis

  • I’m new here
  • *
  • Posts: 14
  • Karma: 0
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.20
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Use Nick Name instead of First Name as Display Name?
February 09, 2011, 11:04:03 am
Removing the braces around contact.first_name also doesn't work. For example, for first_name==William, nick_name==Bill, last_name==Smith, now display name gets set to

"if isset(Bill) Bill Smith"

It appears that the function isset() is not getting evaluated, but simply getting inserted into the result. Interestingly, however, if nick_name is not set, the function works fine.

Perhaps if..then..else is not supported in the "display_name" field generation?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Use Nick Name instead of First Name as Display Name?
February 09, 2011, 11:14:43 am

the display_name is not a smarty template in v3.4 and below. hence if-then-else is not supported etc. We just do token replacements in there

at some point would be good to convert them to smarty templates

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Use Nick Name instead of First Name as Display Name?

This forum was archived on 2017-11-26.