<p>I don't think it's possible to do with out-of-the-box Twig/Craft, but it's a super-easy <a href="http://buildwithcraft.com/docs/plugins/introduction" rel="nofollow">plugin</a> to write.</p>

<p>All you'd need is to give your plugin a <a href="http://buildwithcraft.com/docs/plugins/variables" rel="nofollow">Template Variable</a> so that you could do:</p>

<pre><code>{% if craft.myAwesomePlugin.fileExists('somePath') %}
    YES
{% endif %}
</code></pre>

<p>And your <code>MyAwesomePluginVariable</code> class has a method like:</p>

<pre><code>public function fileExists($path)
{
    return IOHelper::fileExists($path);
}
</code></pre>

CC BY-SA 3.0
2014-11-18T09:58:04.710Z
Thanks Brad, this is a nice clean solution that works well. However, it only checks files that are in the Public directory, and not the Template directory. Going to see if any of the include file functions will be of use. Thanks again.
Mark Notton
CC BY-SA 3.0
2014-11-17T17:28:58.957Z
2014-11-17T17:28:58.957Z
Brad Bell
<p>I have a simple <a href="http://buildwithcraft.com/docs/templating/rss-feed" rel="nofollow">rss feed</a> in my Templates directory, appropriately named "feed.rss". I'm trying to create a link to that file but I don't want that to show up if the file doesn't exist. How might be the best way to only show the link, if the file exists?</p>

<rss>
Check if file exists
# Check if file exists

(Asked by: username_0 on 2014-11-17)

I have a simple [rss feed](http://buildwithcraft.com/docs/templating/rss-feed) in my Templates directory, appropriately named "feed.rss". I'm trying to create a link to that file but I don't want that to show up if the file doesn't exist. How might be the best way to only show the link, if the file exists?

**Tags:** rss


---

## 1 answers

### Answer by username_1 on 2014-11-17. Score: 4 | Accepted answer

I don't think it's possible to do with out-of-the-box Twig/Craft, but it's a super-easy plugin to write.
All you'd need is to give your plugin a Template Variable so that you could do:
{% if craft.myAwesomePlugin.fileExists('somePath') %}
    YES
{% endif %}

And your MyAwesomePluginVariable class has a method like:
public function fileExists($path)
{
    return IOHelper::fileExists($path);
}

> **Comments:**
> **username_0**: Thanks Brad, this is a nice clean solution that works well. However, it only checks files that are in the Public directory, and not the Template directory. Going to see if any of the include file functions will be of use. Thanks again.  

---

