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)
-   -   Smarty Vars (https://forum.x-cart.com/showthread.php?t=36539)

neroag 01-05-2008 03:44 AM

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

PhilJ 01-05-2008 05:44 AM

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

inebriate 01-05-2008 02:24 PM

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

PhilJ 01-05-2008 02:44 PM

Re: Smarty Vars
 
lol, beat me to it

http://www.phpinsider.com/smarty-forum/viewtopic.php?t=7743


All times are GMT -8. The time now is 02:55 PM.

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