Hello! I have a problem here, I can tell me how to solve it just did not come across before.
I created a template loading and page loading function.

function loadPage($smarty, $controllerName, $actionName = "index"){ include_once PathPrefix . $controllerName . PathPostfix; $function = $actionName . "Action"; $function($smarty); } /* * Загрузка шаблона * * $smarty - обьект шаблонизатора * $templateName - название файла шаблона * * методом display() передаем название шаблона как параметр */ function loadTemplate($smarty, $templateName){ $smarty->display($templateName.TemplatePostfix); } 

Created the index.tpl template

 <html> <head> <title>{$pageTitle}</title> </head> <body> {$pageTitle} </body> </html> 

When I type in the line http: //myshop.local/? Controller = index & action = index , I get the following error:

 Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'index.tpl'' in C:\xampp\htdocs\myshop.local\library\Smarty\libs\sysplugins\smarty_internal_templatebase.php:127 Stack trace: #0 C:\xampp\htdocs\myshop.local\library\Smarty\libs\sysplugins\smarty_internal_templatebase.php(362): Smarty_Internal_TemplateBase->fetch('index.tpl', NULL, NULL, NULL, true) #1 C:\xampp\htdocs\myshop.local\library\mainFunctions.php(29): Smarty_Internal_TemplateBase->display('index.tpl') #2 C:\xampp\htdocs\myshop.local\controllers\IndexController.php(18): loadTemplate(Object(Smarty), 'index') #3 C:\xampp\htdocs\myshop.local\library\mainFunctions.php(16): indexAction(Object(Smarty)) #4 C:\xampp\htdocs\myshop.local\www\index.php(13): loadPage(Object(Smarty), 'Index', 'index') #5 {main} thrown in C:\xampp\htdocs\myshop.local\library\Smarty\libs\sysplugins\smarty_internal_templatebase.php on line 127 

I just started to get it right with all of this and I can’t figure out where I’ve done it, tell me about it. Thank!

  • Have you specified the correct path to the file? Smarty does not find the file. - lampa
  • function loadTemplate ($ smarty, $ templateName) {$ smarty-> display ('view / default / index.tpl'); } here even if I have registered it this way, I still do not want to work. strange. - Vitaliisss
  • @Vitaliisss error clearly indicates that your path is incorrect. One is unambiguous. Also check the file permissions. - lampa
  • @lampa I'm completely new to these matters, tell me plz how to check file permissions and if you need to change them? thank! - Vitaliisss
  • @Vitaliisss windows / linux? - lampa

1 answer 1

Hello! Faced the same problem. And immediately the question: why not debazhil?) The author strongly recommended to do it =) When you would see the smarty variable on the screen, you would see this line:

  [joined_template_dir] => ../views/$template\ 

and immediately would understand everything where you have an error =) You just need to edit this line in the config.php file - replace

 define('TemplatePrefix','../views/$template/'); 

on

 define('TemplatePrefix','../views/'.$template.'/'); 

Good luck!