Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

"Firstname, Lastname": Can you count characters?

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 09-06-2010, 02:19 AM
  JeanB's Avatar 
JeanB JeanB is offline
 

eXpert
  
Join Date: Oct 2009
Location: Worcestershire, UK
Posts: 217
 

Default "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
__________________
4.2.3
X-Cart Gold
BCSE Address Book | XCartMods QuickFind | X-RMA | X-Offers
-------[installed]----------------------[installed]--------------[installed]----[installed]--



5: in development
Reply With Quote
  #2  
Old 09-06-2010, 06:50 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default 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.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
  #3  
Old 09-06-2010, 06:55 AM
  JeanB's Avatar 
JeanB JeanB is offline
 

eXpert
  
Join Date: Oct 2009
Location: Worcestershire, UK
Posts: 217
 

Default 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?
__________________
4.2.3
X-Cart Gold
BCSE Address Book | XCartMods QuickFind | X-RMA | X-Offers
-------[installed]----------------------[installed]--------------[installed]----[installed]--



5: in development
Reply With Quote
  #4  
Old 09-06-2010, 07:09 AM
  amy2203's Avatar 
amy2203 amy2203 is offline
 

X-Wizard
  
Join Date: Jul 2004
Location: Watford, UK
Posts: 1,509
 

Default 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
__________________
X-Cart version 5 (Previously 3.5-4)

Previous Versions included
BCSE Reward Points Mod
Altered Cart On Sale Mod
Wordpress Plugin

Please don't PM me for support. I help where I can on the forum and your question will more likely be answered there.

Shout me a Coffee!
Reply With Quote
  #5  
Old 09-06-2010, 07:10 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default 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.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
  #6  
Old 09-06-2010, 07:15 AM
  JeanB's Avatar 
JeanB JeanB is offline
 

eXpert
  
Join Date: Oct 2009
Location: Worcestershire, UK
Posts: 217
 

Default 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!!
__________________
4.2.3
X-Cart Gold
BCSE Address Book | XCartMods QuickFind | X-RMA | X-Offers
-------[installed]----------------------[installed]--------------[installed]----[installed]--



5: in development
Reply With Quote
  #7  
Old 09-06-2010, 07:28 AM
  JeanB's Avatar 
JeanB JeanB is offline
 

eXpert
  
Join Date: Oct 2009
Location: Worcestershire, UK
Posts: 217
 

Default 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!
__________________
4.2.3
X-Cart Gold
BCSE Address Book | XCartMods QuickFind | X-RMA | X-Offers
-------[installed]----------------------[installed]--------------[installed]----[installed]--



5: in development
Reply With Quote
  #8  
Old 09-06-2010, 08:02 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default 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.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 06:38 AM.

   

 
X-Cart forums © 2001-2020