Page 1 of 1

need dynamic path in file-exists query

Posted: Fri Nov 14, 2008 6:24 pm
by glass
I need to find whether a file exists (an image) and then display it if it does exist or ignore if it does not.  That is easy enough.  The problem is that the name of the image I want to discover is not a constant but dynamically determined.

So I need something like this:

Code: Select all

{assign var="articleImg" value="uploads/images/{$entry->title}.jpg"}
{ if file_exists($articleImg) }
	<a href="{$entry->link}"><img src="uploads/images/{$entry->title}.jpg" 
   alt="{$entry->title}" /></a>
{/if}
However the value for the articleImg variable is never valid because of the variable used in the path.

This is probably a simple syntax issue, but I am just not getting this to work.

Any ideas?

Re: need dynamic path in file-exists query

Posted: Fri Nov 14, 2008 6:30 pm
by calguy1000
{capture assign=articleimg}uploads/images/{$entry->title}.jpg{/capture}

Re: need dynamic path in file-exists query

Posted: Fri Nov 14, 2008 6:56 pm
by glass
Many Many thanks!  I knew it was something simple I forgot - doh!  ::)