Jump to content

own plugin doesn't work fine with paths


jorcom

Recommended Posts

Hi Everyone, 
 
i'm working with smarty by first time and i need your help. 
I created my own smarty plugin, this plugin only gets one param, with a path. Then, checks if there are any image (with .jpg extension) inside this path, and put all images found into another array. 
Then, assign the second array into smarty, and i want it to use in a .tpl file, but when i do a foreach in tpl, the plugin works fine, but is checking a sibling folder, not the folder that set into a param when call the function. 
 
I paste my code below to help you understand. 
 

Smarty Plugin:

function smarty_function_getImages($params, &$smarty){ 
   if(!isset($params['directory'])) { 
    trigger_error("Error, path is needed.", E_USER_NOTICE); 
    return; 
   }else{ 
      if(is_dir($params['directory'])){ 
        $aux = scandir($params['directory']); 
        $aux2 = array(); 


        for($i = 0; $i<sizeof($aux); $i++){ 
          if(!is_dir($aux[$i])){ 
            if(substr($aux[$i], -3) == "jpg"){ 
            echo $aux[$i]; 
            array_push($aux2, $aux[$i]); 
            } 
          } 
        }  
        
      $smarty->assign('rightItems',$aux2); 


      }else{ 
        trigger_error("Invalid folder.", E_USER_NOTICE); 
        return "Invalid folder."; 
      } 


   } 
   return; 
}

tpl file

{getImages directory="img/cms/$path/rightItems"} 


{foreach from=$rightItems item=foo} 
    {$foo}<br /> 
{/foreach} 
Someone has had this problem? 
I'm sure that will be a little mistake, but by the moment i don't found the solution 
 

 

 

 

Link to comment
Share on other sites

I finally found the error...

 

another line was calling the same function with another path, the problem is that the line is commented with html tags <!-- and -->

 

smarty comments must be {*    *} 

 

well, this will not forget  :P

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...