View Full Version : question about smarty templates

10-19-2009, 04:56 AM
i have 3 template folders called template1 template2 and template3

in the index.php file when i use the following and access
http://localhost everything works fine and i am able to display the value of variables defined in index.php

$smarty->template_dir = 'c:/wamp/www/smarty/templates';

however when i change to
$smarty->template_dir = 'c:/wamp/www/smarty/templates/template1';
$smarty->template_dir = 'c:/wamp/www/smarty/templates/template2';
$smarty->template_dir = 'c:/wamp/www/smarty/templates/template3';

and when i access http://localhost i am getting the output of
$smarty->template_dir = 'c:/wamp/www/smarty/templates'; where as i have made a small chane in the index.tpl for template1,2and 3 a simple line = template 1 and then followed by displaying the value of variables

why am i getting the output of
$smarty->template_dir = 'c:/wamp/www/smarty/templates/templates';

when i am changing the $smarty to
$smarty->template_dir = 'c:/wamp/www/smarty/templates/template1';

i have cleared the cache and also tried
http://localhost?clearcache=1 and

however i still see the output of
$smarty->template_dir = 'c:/wamp/www/smarty/templates/templates';

please advice.


10-19-2009, 07:15 PM

This is the name of the default template directory. If you do not supply a resource type when including files, they will be found here. By default this is ./templates, meaning that Smarty will look for the templates/ directory in the same directory as the executing php script.

10-19-2009, 11:05 PM
thanks for replying

i did not quite get what you are saying can you explain what i am supposed to do and which code should i change from the below code i have presently


$smarty = new Smarty;

$smarty->template_dir = 'c:/wamp/www/smarty/templates/template1/';
$smarty->config_dir = 'c:/wamp/www/smarty/configs';
$smarty->cache_dir = 'c:/smarty/cache';
$smarty->compile_dir = 'c:/smarty/templates_c';

$smarty->assign('var1','Smarty Template Variable 1 template3');
$smarty->assign('var2','Smarty Template Variable 2 template3');



10-20-2009, 02:43 AM
It doesn't seem like there's much wrong with what you have above. This is what I typically do:

include_once 'Smarty.class.php';
include_once 'Smarty_Compiler.class.php';

// make sure it worked okay
if ( !class_exists('Smarty') )
print "Whoops, no Smarty!";

// initialize smarty
$smarty = new Smarty();

$smarty->template_dir = "$templatedir";
$smarty->compile_dir = SMARTY_DIR . "templates_c";
$smarty->config_dir = SMARTY_DIR . "configs";
$smarty->cache_dir = SMARTY_DIR . "cache";

$smarty->assign( "var", "value!" );
$smarty->display( "main.tpl" );

Which is pretty much the exact same thing you do. So my first guess would just be that you have a bug in your code somewhere - do you happen to have a line that says:

'$smarty->template_dir = 'c:/wamp/www/smarty/templates';'

somewhere outside of your php tags? I really can't think of any other reason why it would output exactly that statement, other than having a mis-placed line of code outside of php tags, and therefore interpreted as plain text.