Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2008
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Smarty {if file_exists}

    Hi there. I've been working with Flynax's auto classifieds script, which is the first I've ever seen or used Smarty. And honestly, I'm not the best with regular PHP to begin with. So please pardon me while I ask a potentially dumb question.

    On the dealer profile pages of our site (http://www.theusedcarplace.com/index...accounts&id=24), I'm using the following code to pull in a JPG of the dealer's most recent print ads.

    Code:
    <div class="print-ads"> 
    <a href="http://www.theusedcarplace.com/print-ads/{$account.Full_name|replace:" ":"_"|lower}.pdf" target="_blank"><img src="http://www.theusedcarplace.com/print-ads/{$account.Full_name|replace:" ":"_"|lower}.jpg" /> 
    <p>Click to View PDF</p> 
    </a> 
    </div>
    The problem is, on pages for dealers who haven't run a print ad (http://www.theusedcarplace.com/index...-accounts&id=4), there obviously isn't a corresponding JPG, so I get a missing image.

    If possible, I'd like to use an {if} statement to show the JPG if it exists, but to show nothing if it does not. Here's what I've been playing with...

    Code:
    {assign var="printad" value="/print_ads/{$account.Full_name|replace:" ":"_"|lower}.jpg"} 
    {if file_exists($printad)} 
    <div class="print-ads"> 
    <a href="/print-ads/{$account.Full_name|replace:" ":"_"|lower}.pdf" target="_blank"><img src="/print-ads/{$account.Full_name|replace:" ":"_"|lower}.jpg" /> 
    <p>Click to View PDF</p> 
    </a> 
    </div> 
    {/if}
    ...Except that doesn't work. It pretty much breaks the entire site. Could that be because of the nested brackets in the first line? Because the following doesn't really work either, but at least it doesn't result in a white page...

    Code:
    {assign var="printad" value='/print-ads/[$account.Full_name|replace:" ":"_"|lower].pdf'}
    {if file_exists($printad)}
    <img src="/print-ads/{$account.Full_name|replace:" ":"_"|lower}.jpg" />
    {else}
    0
    {/if}
    Any suggestions? Please keep in mind that I'm a coding idiot.

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    this isn't php. try the smarty forum: http://www.smarty.net/forums/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •