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)
-   -   Truncating to the FIRST Character in a variable (https://forum.x-cart.com/showthread.php?t=4787)

rodneyw 10-15-2003 12:06 PM

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!

groovico 10-15-2003 12:28 PM

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.

rodneyw 10-15-2003 12:34 PM

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}


funkydunk 10-15-2003 12:46 PM

try:

Code:

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



This will work on the product reviews.

rodneyw 10-16-2003 03:47 AM

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 :)

rodneyw 10-16-2003 04:21 AM

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??

groovico 10-16-2003 06:32 AM

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


All times are GMT -8. The time now is 12:58 AM.

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