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

smarty help please? can I compare the first x characters of a variable?

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 12-02-2007, 09:46 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default smarty help please? can I compare the first x characters of a variable?

Smarty help, please?

I am seeking to compare the first x characters of a var string - for example:

let's says there's a variable: $variablename

{if $variablename 1st 5 characetrs = 1ZAB1}
then show something
{else}
show something else.

Can this be done in smarty?

My goal is to trap the first 5 characters of a tracking number -- and if it looks like 1ZAB1, then it is clearly UPS, and I will show a UPS tracking link. ELSE it can only be USPS (and a different tracking link)

Any ideas?

Thanks.

Jeremy
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #2  
Old 12-02-2007, 09:49 PM
 
inebriate inebriate is offline
 

eXpert
  
Join Date: May 2006
Posts: 301
 

Default Re: smarty help please? can I compare the first x characters of a variable?

{if $variablename|substr:0:5 eq '1ZAB1'}
__________________
x-cart pro 4.0.18
linux
www.fabric8d.com (currently undergoing construction)
Reply With Quote
  #3  
Old 12-02-2007, 09:57 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: smarty help please? can I compare the first x characters of a variable?

Quote:
{if $variablename|substr:0:5 eq '1ZAB1'}

that is just BEAUTIFUL!

thank you!

Jeremy
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #4  
Old 12-02-2007, 10:34 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: smarty help please? can I compare the first x characters of a variable?

question: can the substr be case iNSEnsiTIvE?

so: if the string is 1zAb12v41234567

OR the string is:

1ZAB12V41234567

the results are the same?

is the there a smarty "case doesn't matter" setting?

thx

Jeremy
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #5  
Old 12-02-2007, 11:22 PM
  Ene's Avatar 
Ene Ene is offline
 

X-Cart team
  
Join Date: Aug 2004
Posts: 907
 

Arrow Re: smarty help please? can I compare the first x characters of a variable?

PHP Code:
{if $variablename|substr:0:5|upper eq '1ZAB1'
__________________
Eugene Kaznacheev,
Evangelist/Product Manager at Ecwid: http://www.ecwid.com/ (since Sept 2009)

ex-Head of X-Cart Tech Support Department
ex- X-Cart Hosting Manager - X-Cart hosting
ex-X-Cart Technical Support Engineer


Note: For the official guaranteed tech support services please turn to the Customers HelpDesk.
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 09:58 AM.

   

 
X-Cart forums © 2001-2020