Show initial of Last Name Field

trupal218 - September 2, 2009 - 08:42
Project:Views Custom Field
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hello,

First and foremost, thank you very much for a great module and the support base!

I was wondering if it is possible to get the initial of the last name in a field.
i.e. Last name: Johnson => to show as "J." in the field

Thank you very much in advance!

#1

casey - September 2, 2009 - 09:01

<?php
echo $data->node_data_field_lastname[0] . '.';
?>

or

<?php
echo substr($data->node_data_field_lastname, 0, 1) . '.';
?>

#2

trupal218 - September 2, 2009 - 11:29

Hello casey!

Thank you for the quick support.

Using the above code I am only seeing a " . " for the field in the view.
I'm sorry I forgot to mention that I am using content profile (if it may have an impact on the code).

Also, is it necessary to have any arguments/relationships?

I apologize but not familiar with php programming, and currently starting to learn from guides available online.

Thank you!

#3

casey - September 2, 2009 - 14:44

1. You have to add the lastname field to the view (and exclude it from display).
2. I am just using an example variable. You have to find out what the name of the needed variable is. For this you can use

<?php
print_r
($data);
?>

#4

trupal218 - September 2, 2009 - 23:14

From what I have learning from php guides in the past week, it just clicked from your explanation!
I will try adding lastname field to the view and exclude it from display, then print_r to get the variable.

As a side note - would this be the only way of doing this?

Thanks casey!

 
 

Drupal is a registered trademark of Dries Buytaert.