X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   "Firstname, Lastname": Can you count characters? (https://forum.x-cart.com/showthread.php?t=55411)

JeanB 09-06-2010 02:19 AM

"Firstname, Lastname": Can you count characters?
 
Hi All,
I have a bar along the top of my site that tells you who's logged in.

Code:


{if $login eq "" }
You are not logged in! <strong><a href="../error_message.php?need_login">[Login]</a></strong>
{else}
<strong>{if ($active_modules.Greet_Visitor ne "") AND ($smarty.cookies.GreetingCookie ne "")}{$smarty.cookies.GreetingCookie|replace:"\'":"'"}</strong>
{/if}
{$lng.txt_logged_in}<br />
{/if}


However, I only have a limited amount of space to fit a name in, before it starts overlapping something else.

I wondered if there was a way to count how many characters are in the person's name - If it's over a certain amount, only display their first name?

Thanks in advance,
Jean 8-[

geckoday 09-06-2010 06:50 AM

Re: "Firstname, Lastname": Can you count characters?
 
This will truncate the greeting at or before 30 characters at a word boundary.

{$smarty.cookies.GreetingCookie|replace:"\'":"'"|t runcate:30:"":true}

See http://www.smarty.net/manual/en/language.modifier.truncate.php for details on the truncate modifier.

JeanB 09-06-2010 06:55 AM

Re: "Firstname, Lastname": Can you count characters?
 
Hi Ralph,
Thank you very much for the response,

However, I don't really want to truncate, as such. I would rather count how many characters there are and only display the first name, if the total is greater than a given value.

So, if someone's name was 'John Smith', that would display in full. But if someone else's name was 'Hubert Wolfeschlegelsteinhausenbergerdorff', It would only display 'Hubert'.

(If the characeter limit was 30.)

I hope this makes sense?

amy2203 09-06-2010 07:09 AM

Re: "Firstname, Lastname": Can you count characters?
 
it should do this as it will only truncate at a word boundary, so the gap between first and last name? if the first and last is 30 or below (for example), it will display both, if the first and last name is larger than 30 it will truncate at the boundary, and only display the first name,

hth

geckoday 09-06-2010 07:10 AM

Re: "Firstname, Lastname": Can you count characters?
 
That's why I set the flag to truncate on a word boundary so it would truncate the whole last name if its over 30 characters. The only problem you should run into is a long first name with a two part last name like Robertthegreatestmanalive Van Buren which will display as Robertthegreatestmanalive Van or first names longer than you have room for.

To do exactly what you want you'll need to modify the php code in a couple of places where the cookie gets set - login and register I believe, search for "greet" to find the spots. The cookie will only get updated when customers login so it may take a while before it gets propagated to all users. Or you could change the cookie name and start all users over with no greeting.

JeanB 09-06-2010 07:15 AM

Re: "Firstname, Lastname": Can you count characters?
 
Ooops - Completely my mistake - Sorry Ralph! ](*,)

In that case - That's wonderful, thank you ever-so! I shall sort that out now and report back!

Thanks, both - Really appreciate it!! :wink:

JeanB 09-06-2010 07:28 AM

Re: "Firstname, Lastname": Can you count characters?
 
I had to take the "true" off the end, because it was truncating exactly at 30?

Now works brilliantly:

Trevor Test:

http://i16.photobucket.com/albums/b49/BeanJardo/Work/trevortest.jpg


Trish Wolfeschlegelsteinhausenberger:

http://i16.photobucket.com/albums/b49/BeanJardo/Work/trish.jpg

Hurrah!


Thanks both - Very happy!

geckoday 09-06-2010 08:02 AM

Re: "Firstname, Lastname": Can you count characters?
 
Yep, I got the idea right but the details wrong. I forgot the default for truncate was a word boundary and setting the flag to true was for exact length truncation. Gotta read the doc a little closer next time. Glad its working.


All times are GMT -8. The time now is 05:23 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.