Smarty is not choosing the correct templates to di

2019-08-20 01:21发布

问题:

I was working on a website yesterday and all was well. I was porting it to use Smarty. I had one last page to change which didn't require any testing since the Smarty template file didn't really do much. I saved my work, closed everything out, and left. Earlier today, I checked the site and found that it has gone haywire. It is displaying an incorrect template for all but one page. I never changed anything with my server setup so that can't be the problem. Pages that had previously worked flawlessly no longer work. I've quintuple-checked my work and can't see what's going wrong. In order to not post every single thing I have, I will share any code of mine that you would like to take a look at. Just leave a comment, and I will make an edit. Any ideas what could be going wrong? I am using Smarty 3.1.8 and PHP 5.3.3.

Live site

回答1:

The mix-up is occurring because (almost) all of the templates are named the same thing. As per this thread, I found that when Smarty compiles the templates, it only considers the file name, not the full path to that file. Therefor, you must specify a compile ID, which for this purpose is best to be the parent directory of the currently executing script. If you use just the __FILE__ constant, you may end up with multiple compilations of the same template if you use multiple scripts in the same directory to display the same template. So I use dirname(__FILE__) for my compile ID which should work for everybody.



标签: php smarty