Re: custom functions
| From: | chiefmonkey | Date: | Thu, 21 Feb 2002 09:08:50 +0000 |
| Subject: | Re: custom functions | ||
| References: | 1 2 3 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2806@lists.php.net to get a copy of this message | ||
Line 868 is while(false !==($file = readdir($handle)))
which when changed to
while(false !=($file = readdir($handle))) or while(($file = readdir($handle)))
Results in
http://www.experimentalmonkey.co.uk/screenshot2.gif
George
At 16:28 20/02/2002 -0600, Monte Ohrt wrote:
and what is line 868 in addons? chiefmonkey wrote: Had a look at the page in opera and got the following resulthttp://www.experimentalmonkey.co.uk/opera_screenshot.gifGeorge At 15:43 20/02/2002 -0600, Monte Ohrt wrote:It looks like it is trying to do the right thing. put some debugging echos in there to see if is doing what you expect, or if the function is even being executed. chiefmonkey wrote:binaryHere's the function function smarty_func_getimage($path) { $imagelist=array(); $handle=opendir($path); while(false !==($file = readdir($handle))) { if ($file !="." && $file !="..") { $ext=substr($file, -4); // if you wish to add .png to the list of files // uncomment the line below and delete the original line //if ($ext == ".jpg" || $ext==".gif" || $ext==".png") { if ($ext == ".jpg" || $ext==".gif") { array_push($imagelist, "$file"); } } } srand((double) microtime()* 1000000); $names=$imagelist; $rand_keys = array_rand($names,2); $adimage=$names[$rand_keys[0]]; $alt=substr($adimage,0,-4); $adimage="$path/".$adimage; $size=GetimageSize($adimage); $display="<img src=\"$adimage\" $size[3] alt=\"$alt\" />"; echo"$display"; closedir($handle); } Thanks for the help so far George At 15:31 20/02/2002 -0600, Monte Ohrt wrote:OK, and then what does it do? It shouldn't try to send the imagepath toto the template, if that is what it's doing. It should return aan errorthe image, so the browser will go back after the template loads to get the image. so something like this in your template: <img src="{getimagepath}"> where getimagepath would display the path to the image relative to the document root. chiefmonkey wrote:It grabs an image at random from a specified directoryGeorgeAt 15:23 20/02/2002 -0600, Monte Ohrt wrote:What does getimage do exactly? dump image data to the browser? chiefmonkey wrote:I now have it working, in as much as it doesn't displaySmarty.classcrashing now.message, however the browser window won't load and it keepsGeorge At 15:11 20/02/2002 -0600, Monte Ohrt wrote:wrong syntax for one: {getimage name="val" name2="val2"} chiefmonkey wrote:I am trying to create a custom function so I added it to Smarty.addons and named it smarty_func_getimage I then added it to the custom functions array inhttp://www.phpinsider.com/php/code/Smarty/http://www.phpinsider.com/php/code/Smarty/http://www.phpinsider.com/php/code/Smarty/$subst('Email.Unsub')'getimage' => 'smarty_func_getimage'and I am trying to call it from my template {getimage:"path/to/images"} but I keep getting this error syntax error: unknown tag - 'getimage TIA George --- You are currently subscribed to smarty as: monte@ispi.net To unsubscribe send a blank email toVisit Smarty's homepage at$subst('Email.Unsub')-- Monte Ohrt <monte@ispi.net> http://www.ispi.net/--- You are currently subscribed to smarty as: monte@ispi.net To unsubscribe send a blank email toVisit Smarty's homepage at$subst('Email.Unsub')chiefmonkey@wisemonkeydesign.co.uk-- Monte Ohrt <monte@ispi.net> http://www.ispi.net/ --- You are currently subscribed to smarty as:To unsubscribe send a blank email toVisit Smarty's homepage at$subst('Email.Unsub')chiefmonkey@wisemonkeydesign.co.uk-- Monte Ohrt <monte@ispi.net> http://www.ispi.net/ --- You are currently subscribed to smarty as:To unsubscribe send a blank email tochiefmonkey@wisemonkeydesign.co.uk-- Monte Ohrt <monte@ispi.net> http://www.ispi.net/ --- You are currently subscribed to smarty as:Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/To unsubscribe send a blank email to $subst('Email.Unsub') Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/-- Monte Ohrt <monte@ispi.net> http://www.ispi.net/ --- You are currently subscribed to smarty as: chiefmonkey@wisemonkeydesign.co.uk To unsubscribe send a blank email to $subst('Email.Unsub') Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/