Jump to content

Check a URL in smarty?


mohsart
 Share

Recommended Posts

I have code like this

{if $product->supplier_reference}
supplier_reference}.html#review" target="_blank">gobooks.nemir.org {l s='(May result in a error if book does not exist on that webpage)'}
{/if}


that show a link to a website that has revews on many (but not all) of the books that I sell.

So, I'd like to check if the page exists and only show the link if it does. Is this possible?

Edit: code broke of course, but I think my point is clear enough

/Mats

Share this post


Link to post
Share on other sites

I think you can use code like the following in product.tpl:

{if $product->supplier_reference AND file_exists($product->supplier_reference|cat:'.html')}



You may need to add a path before the filename for it to work though.

Share this post


Link to post
Share on other sites

Sorry if I was unclear, it's a URL on a remote website that I want to check.
I tried some variations of entering the URL in file_exists() but I suspect that it only works for local files?

/Mats

Share this post


Link to post
Share on other sites

You are right that file_exists only works for local files. I tried using fopen to check whether the file exists, but I can't get it to work with Smarty. I think you'll need to write code to check whether the file exists in product.php and then pass in the variable only if it exists.

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More