|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Jose Smarty n00b
Joined: 08 Sep 2017 Posts: 2
|
Posted: Fri Sep 08, 2017 4:25 pm Post subject: Check if a file exists "$tpl_dir./test.html" |
|
|
Good afternoon, I'm trying to include a html file in a section inside the product sheet.
For this I have included in the product.tpl this code:
Code: | {include file="$tpl_dir./test.html"} |
In this case it is a test, but I want the file name to be the Product Code.html. It also works fine, but if that file does not exist, it gives an error.
In php it is simple to check if that url or file exists. But I do not know how to do it on smarty.
I've tried introducing php code between tags {php} {/ php}, but it does not work, as I've seen it is obsolete.
You could tell me some way, to check the availability of that file, to put it in an if, that only enters when it exists ...
Thank you very much for your help. I've been behind this for many hours and I do not know where to go.
Thank you!! |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sat Sep 09, 2017 3:59 am Post subject: |
|
|
I would try:
Code: | {if file_exists("$tpl_dir/test.html")}
{include file="$tpl_dir/test.html"}
{else}
{include file="$tpl_dir/404.html"}
{/if} |
Many PHP functions are usable in Smarty. |
|
Back to top |
|
Jose Smarty n00b
Joined: 08 Sep 2017 Posts: 2
|
Posted: Sat Sep 09, 2017 6:27 am Post subject: Thanks |
|
|
Thank you very much, it works perfectly. It was much simpler than I thought. Thanks again, you take away a big problem from above !! |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Sep 11, 2017 3:12 pm Post subject: Re: Check if a file exists "$tpl_dir./test.html" |
|
|
Jose wrote: | but if that file does not exist, it gives an error. | Of course it gives an error. Because you made it - you told it to include a nonexistent file. And it is your responsibility to fix it. Not to mask it with senseless workarounds. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|