Smarty syntax help

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
grimmus
Forum Members
Forum Members
Posts: 28
Joined: Sun Jan 11, 2009 7:17 am

Smarty syntax help

Post by grimmus »

Hi,

I have a UDT that outputs logo images from a certain folder based on what section the user is in.

I need these images to link to their product websites, so i have named the images like
www-google-com.gif, www-facebook-com.gif

My plan is to extract the link from the image name but the smarty syntax isnt working for me.

I need to replace the slashes with dots and remove the file extension (.gif, .jpg etc.)

i have something like

Code: Select all

$files = glob("uploads/images/".$params['id']."/*.*", GLOB_BRACE);

if($files)
{
$folder = $params['id'].'/';

$i=1;
foreach($files as $file)
{
        if(!preg_match('/thumb/',$file))
        {            
             //$image = explode('.',$files[$i]);
             
             $image = explode('-',$files[$i]);
             $im = explode($folder,$image[0]);
             $thumb = explode($folder,$file);
             $path =  $thumb[0].$folder.'/'.$thumb[1];

                  print"<a href='$image[$i]' >";
                  print" <img src='".$path."' />";
                  print "</a>";         
        }        
}

}

Could anyone help me with the syntax ? I want to replace the slashes with dots and remove the file exension (including the dot)

Thanks for any help
Peciura

Re: Smarty syntax help

Post by Peciura »

Why cant you name your files like "www.gooogle.com" ?

You placed your variable "$image[$i]" between ' and '

Code: Select all

<?php
print"<a href='$image[$i]' >";
?>
, i think output is as literal string "".
Try

Code: Select all

<?php
print"<a href=\"$image[$i]\" >";?>
or similar as you have already done

Code: Select all

<?php
print"<a href='".$image[$i]."' >";
?>

Code: Select all

<?php
if(!preg_match('/thumb/',$file)){  
   $path_parts = pathinfo($file);
   $path_parts['filename'];
   print"<a href=' ".str_replace( '-', '.', $path_parts['filename'])." ' >";
   print" <img src='".$file."' />";
   print "</a>"; 
}        
?>
Any way this should help
http://lt2.php.net/manual/en/function.pathinfo.php
http://lt2.php.net/manual/en/function.str-replace.php
Post Reply

Return to “Developers Discussion”