Bojan Peovski
Bojan Peovski

Reputation: 11

Smarty Template Organization

I've set up Smarty and my basic structure is this:

www.domain.com/html -- This is where all the .php files live. www.domain.com/smarty/templates -- This is where all the .tpl files live.

Now, everything works well for files in the web root directory (html), but I'm not sure what to do when I put .php files in a separate folder under the root e.g. www.domain.com/html/folder/. I want to do this to organize a bunch of related pages under that new folder. I still place all the .tpl files under the www.domain.com/smarty/templates folder. When I try to display a page under that new folder e.g. ww.domain.com/html/folder/, the resources for the page (CSS, images, etc.) are missing i.e. are not being fetched. What's the proper way to organize the files for this scenario?

Thank you.

Upvotes: 1

Views: 219

Answers (1)

Jack
Jack

Reputation: 1386

Make sure your config for template_dir, compile_dir, cache_dir, and config_dir are using full absolute path (ex. /home/httpd/vhosts/[yourdomain.com].... or whatever it is with a trailing /).

Make sure you reference your CSS/Images using absolute path from the root. So if your css is in a folder [ROOT]/css, your HTML would call the CSS like this: <link rel="stylesheet" href="/css/main.css" type="text/css">

It doesn't matter where the templates are and where your PHP files are. When they are loaded into PHP the template is just that, a template, and all your pathing takes place from the perspective of the PHP file.

Upvotes: 1

Related Questions