4

How do I check if file exists in Smarty 2? I mean something like this:

{assign var="module_js" value="/js/modules/{$module}.js"}
{if file_exists($module_js)}
    <script type="text/javascript" src="{$module_js}"></script>
{/if}
Yekver
  • 4,985
  • 7
  • 32
  • 49

1 Answers1

6

Actually this has nothing to do with the Smarty-version. But the way you are assigning the variable is wrong. Try this way:

{assign var="module_js" value="js/`$module`.js"}
{if file_exists($module_js)}
    <script type="text/javascript" src="{$module_js}"></script>      
{/if}
Stephan Weinhold
  • 1,623
  • 1
  • 28
  • 37
Sibu
  • 4,609
  • 2
  • 26
  • 38