Smarty is not choosing the correct templates to display

瘦欲@ 提交于 2019-12-12 05:02:33

问题


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.



来源:https://stackoverflow.com/questions/10575213/smarty-is-not-choosing-the-correct-templates-to-display

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!