Jump to content

Smarty Engine | Newbie Questions


JustinK101

Recommended Posts

Hello all, I just found out about smarty and looking forward to using it. I do have a few questions. Here is how I have smarty setup.

This is the full path to the smarty engine and libs directory. This directory is not web accessible.

[code]
/home/username/smarty/
[/code]

The next directory 'smarty_templates' will hold all my of projects, each project will have it's own folder and associated: templates_c, templates, config, and cache folder. This is web accessible, obviously!

[code]
/home/username/public_html/smarty_templates/
[/code]

I have multiple projects which use smarty but I want to keep them seperate. [b]Is this the right way of going about doing it?[/b] I.E. making a 'smarty_templates' directory then having a 'project_1' folder which has its own 'templates_c', 'templates', 'cache', and 'config' folder. Then another project, 'project_2', which has its own 'templates', 'templates_c', 'cache', and 'config' directories.

The directory strucuture will look like this:

[code]
smarty_templates
     project_1
          templates_c
          templates
          cache
          config
     project_2
          templates_c
          templates
          cache
          config
[/code]

[b]My second question, how can I make it easier to reference the smarty class and the associated templates associated with a project?[/b]

Currently I have to type the full path name for every template which is kind of a pain in the butt. This full path is going to be global, every project will use them, so I want to set them to default for every project without typing the entire paths as I show below.

[code]
require('/home/username/smarty/libs/Smarty.class.php');
$smarty = new Smarty();

$smarty->template_dir = '/home/username/public_html/smarty_templates/project_1/templates';
$smarty->compile_dir = '/home/username/public_html/smarty_templates/project_1/templates_c';
$smarty->cache_dir = '/home/username/public_html/smarty_templates/project_1/cache';
$smarty->config_dir = '/home/username/public_html/smarty_templates/project_1/configs';
[/code]

Is there a way I can hard code, set a global variable for these full paths so I can simply do:

[code]
require('Smarty.class.php');
$smarty = new Smarty();

$smarty->template_dir = 'project_1/templates';
$smarty->compile_dir = 'project_1/templates_c';
$smarty->cache_dir = 'project_1/cache';
$smarty->config_dir = 'project_1/config';
[/code]

You see how much eaiser and better that looks.

[b]Lastly, what is the config directory for anyway?[/b] I mean this directory will be defined for every project, so how does it work?

Thanks Guys!
Link to comment
https://forums.phpfreaks.com/topic/11564-smarty-engine-newbie-questions/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.