Question

I am using smarty 3 .its not working in subfolder.

Folder Structure

WWW
->admin 
->cache
->configs
->libs
->plugins
->templates
->templates_c
index.php

In index.php [Root Folder] it working correctly.

But in admin/index.php it not working i am getting error.

here is my code

require_once('../libs/Smarty.class.php');

$smarty = new Smarty;

$smarty->display('index.tpl');

Error :

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'index.tpl'' in D:\wamp\www\libs\sysplugins\smarty_internal_templatebase.php on line 127

After reading some stackoverflow answer i added $smarty->template_dir = "/templates"; but still i am getting the same error.

Please help me thank you

Was it helpful?

Solution

The content of $smarty->template_dir is relative to the actual directory. (if it is a relative directory.) It means if you call a admin/index.php then it searches the templates in the admin/templates directory by default. (without adding anything.)

So in the admin directory you should use:

$smarty->template_dir = "../templates";

or an absolute directory.

Otherwise I think you should read this page:

http://www.smarty.net/docs/en/variable.template.dir.tpl

Especially this sections:

It is not recommended to put this directory under the web server document root.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top