need dynamic path in file-exists query

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
glass
Forum Members
Forum Members
Posts: 32
Joined: Tue Sep 09, 2008 4:51 pm

need dynamic path in file-exists query

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: need dynamic path in file-exists query

Post by calguy1000 »

{capture assign=articleimg}uploads/images/{$entry->title}.jpg{/capture}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
glass
Forum Members
Forum Members
Posts: 32
Joined: Tue Sep 09, 2008 4:51 pm

Re: need dynamic path in file-exists query

Post by glass »

Many Many thanks!  I knew it was something simple I forgot - doh!  ::)
Post Reply

Return to “The Lounge”