简体   繁体   中英

Joomla Greeting Name to only show first word

In the Joomla (v3) logout form, it is showing the registered users full name they registered with.

echo JText::sprintf('MOD_LOGIN_HINAME', htmlspecialchars($user->get('name')));

Rather than showing:

Fred Bloggs

I only want to show:

Fred

What is the easiest way to edit the above to show just the first word from the $user->get('name')

Before doing anything, please don't override the file. Instead, create a Template Override so that when you update Joomla, your changes are not overridden.

Once done, you can use strstr which finds ehe first occurrence of a string, like so:

$name = strstr($user->get('name'), ' ', true);
echo JText::sprintf('MOD_LOGIN_HINAME', htmlspecialchars($name));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM