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

Truncating to the FIRST Character in a variable

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-15-2003, 12:06 PM
 
rodneyw rodneyw is offline
 

Senior Member
  
Join Date: Mar 2003
Posts: 162
 

Default Truncating to the FIRST Character in a variable

trying to modify the customer reviews so that it doesn't automatically populate the name with the full name and email address of the customer.

Removing the email address was easy enough but now I am trying to have it default to just their first initial and last name .. or first name and last initial but I do not know how to modify the variable to only display the first character.
Code:
{if $login ne ""} value="{$customer_info.firstname} {$customer_info.lastname}" {/if}


any ideas? Thanks!
Reply With Quote
  #2  
Old 10-15-2003, 12:28 PM
  groovico's Avatar 
groovico groovico is offline
 

X-Man
  
Join Date: Apr 2003
Location: Firetanksoftware.com
Posts: 2,326
 

Default

Take a look at the customer/main/products.tpl note the truncate command smarty has in there to reduce the short description to 300 chars, you can use the same code to accomplish what you want here.
__________________
Groovico

Used by X-carters the world over:
Marketing Manager Pro Bundle For X-cart
Featured Product Manager for X-cart
Feed manager pro for X-cart

http://www.firetanksoftware.com

Celebrating 7 Years of providing quality X-cart Add ons and X-cart Mods for x-cart 3.X to X-cart 4.4.X
Reply With Quote
  #3  
Old 10-15-2003, 12:34 PM
 
rodneyw rodneyw is offline
 

Senior Member
  
Join Date: Mar 2003
Posts: 162
 

Default

the problem is that I need the FIRST character .. so if a name is 8 characyers long I need to use the FIRST one.

FirstName LastName = F. LastName

here is what I am in the progress of working on that seems to work. It's not pretty but seems to work for the most part

Code:
{assign var="count1" value=$customer_info.firstname|count_characters:true} {math equation="x-y" x=$count1 y=1 assign="count2"} {if $login ne ""} value="{$customer_info.firstname|truncate:$count2:"."} {$customer_info.lastname}" {/if}
Reply With Quote
  #4  
Old 10-15-2003, 12:46 PM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

try:

Code:
{if $login ne ""} value="{$customer_info.firstname|truncate:2:".":true} {$customer_info.lastname}" {/if}


This will work on the product reviews.
__________________
ex x-cart guru
Reply With Quote
  #5  
Old 10-16-2003, 03:47 AM
 
rodneyw rodneyw is offline
 

Senior Member
  
Join Date: Mar 2003
Posts: 162
 

Default

ok, that was what it looked like in the example that Groovico pointed me to but thought that wouldn't work.

I was all over smarty.php.net and went back after your post. I guess what threw me was the description of what the parameter TRUE did.

Quote:
This determines whether or not to truncate at a word boundary (false), or at the exact character (true).

Thanks!!!, wish I wouldn't have spent as much time as I did on figuring THAT one out though
Reply With Quote
  #6  
Old 10-16-2003, 04:21 AM
 
rodneyw rodneyw is offline
 

Senior Member
  
Join Date: Mar 2003
Posts: 162
 

Default

i get it now. by setting it to TURE then it does the WORD and since most people only use 1 first name then this works. But if someone uses a 2 word first name then it will only truncate the last one .. right?

like: Lisa Marie Smith = Lisa M. Smith

Right??
Reply With Quote
  #7  
Old 10-16-2003, 06:32 AM
  groovico's Avatar 
groovico groovico is offline
 

X-Man
  
Join Date: Apr 2003
Location: Firetanksoftware.com
Posts: 2,326
 

Default

Best way of working stuff like that out is simply to do quick tests

{$customer_info.firstname|truncate:2:".":true}
{$customer_info.firstname|truncate:2:".":False}

And just view the effects
__________________
Groovico

Used by X-carters the world over:
Marketing Manager Pro Bundle For X-cart
Featured Product Manager for X-cart
Feed manager pro for X-cart

http://www.firetanksoftware.com

Celebrating 7 Years of providing quality X-cart Add ons and X-cart Mods for x-cart 3.X to X-cart 4.4.X
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:26 AM.

   

 
X-Cart forums © 2001-2020