Jaguaro Posted August 10, 2014 Share Posted August 10, 2014 Good afternoon, I've inserted two lines of code on the manufacturer.tpl file, to display the logo on the manuf.'s page. I would like to error check it, because I have a few manufacturers without logo. Here is my code: {assign var="myfile" value="{$base_dir}img/m/{$manufacturer->id}.jpg"} <img src="{$base_dir}img/m/{$manufacturer->id}.jpg" /> <br/> I would like to display it only if the file exists. I tried this, but it doesn't work: {assign var="myfile" value="{$base_dir}img/m/{$manufacturer->id}.jpg"} <if file_exist($myfile)> <img src="{$base_dir}img/m/{$manufacturer->id}.jpg" /> <br/> </if> How can I fix it? Thanks, C Link to comment Share on other sites More sharing options...
vekia Posted August 10, 2014 Share Posted August 10, 2014 smarty use brackets, not <> so your code will not work {if file_exists('../path/to/file.jpg')} ... {/if} Link to comment Share on other sites More sharing options...
Jaguaro Posted August 10, 2014 Author Share Posted August 10, 2014 (edited) Thank you Vekia,Anyway I wrote the wrong code up here, I know that it requires brackets. After long troubleshooting I understood that my server ( Aruba ) doesn't accept the absolute path for the file_exists function. The code below works because it's with relative path. {assign var="myfile" value="img/m/{$manufacturer->id}.jpg"} {if file_exists($myfile)} <img src="{$base_dir}img/m/{$manufacturer->id}-large_default.jpg" /> <br/> {/if} Thanks! Edited August 10, 2014 by Jaguaro (see edit history) 2 Link to comment Share on other sites More sharing options...
vekia Posted August 10, 2014 Share Posted August 10, 2014 great! thanks for sharing this snippet im more than convinced that it will be helpful for other merchants here :-) i marked topic title as [solved] with regards,Milos Link to comment Share on other sites More sharing options...
Maxence de Flotte Posted December 13, 2018 Share Posted December 13, 2018 (edited) Hi, Sorry for the late response. But for other members with the same problem, using a relative path is not a good idea. $base_dir is not the full path but the path on your URL. You need to use _PS_IMG_DIR_. Assign the variable on your module / controller 514 $this->smarty->smarty->assign( 515 'rm_img_dir', 516 _PS_IMG_DIR_ 517 ); On your template, create the var with the fullpath {assign var="icon_full_path" value="{$rm_img_dir}rm/c{$subcategory->id}.png"} And use it on your template : {if file_exists($icon_full_path)}...{/if} Best regards, Edited December 13, 2018 by Maxence de Flotte (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now