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

Smarty Vars

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 01-05-2008, 03:44 AM
 
neroag neroag is offline
 

Senior Member
  
Join Date: May 2005
Location: UK
Posts: 171
 

Default Smarty Vars

Hi all

Is there a way that i can pass the contents of a smarty variable to a php varible within {php} to perform php a php function?

Basically Im trying to find a way of checking if a selected smarty variable contains a certain string IE.. does {$product.product} contain the word "Cheap" for example.

Thanks all
__________________
X-cart Gold - 4.0.18 - 4.1.9 - 4.1.10 - 4.3.0
Reply With Quote
  #2  
Old 01-05-2008, 05:44 AM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default Re: Smarty Vars

Here's one way of doing it...

Code:
{php} $foo = $this->get_template_vars( 'product' ); $bar = $foo['product']; $woof = $foo['productcode']; echo "<br />"; echo "$bar"; echo "<br />"; echo "$woof"; echo "<br /><br />"; $findme = 'Cheap'; $look = strpos($bar, $findme); if ($look == false) { echo "The string '$findme' was not found in the string '$bar'"; } else { echo "The string '$findme' was found in the string '$bar'"; echo " and exists at position $look"; } {/php}

There's probably an easier way using smarty alone, I'll keep looking...
__________________
xcartmods.co.uk
Reply With Quote
  #3  
Old 01-05-2008, 02:24 PM
 
inebriate inebriate is offline
 

eXpert
  
Join Date: May 2006
Posts: 301
 

Default Re: Smarty Vars

{$product.product|strpos:"Cheap"}

problem with using strpos though is you need to run another check if "Cheap" is at the 0 position, if its not there strpos will still evaluate it as 0

so you need to use something like substr to compare if its actually at the 0 position or not
__________________
x-cart pro 4.0.18
linux
www.fabric8d.com (currently undergoing construction)
Reply With Quote
  #4  
Old 01-05-2008, 02:44 PM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default Re: Smarty Vars

lol, beat me to it

http://www.phpinsider.com/smarty-forum/viewtopic.php?t=7743
__________________
xcartmods.co.uk
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 10:02 PM.

   

 
X-Cart forums © 2001-2020