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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.