Quick Smarty Install

In Debian Etch:

Now you have a Smarty install. To use it, you'll need PHP code to drive Smarty. I'll include a sample bit of PHP code that I was working on with Mike A:



        $smarty = new Smarty();

        $dir = '/var/www-sites.d/malborn.pachogrande.com';

        $smarty->template_dir = $dir . '/smarty/templates';

        $smarty->compile_dir = $dir . '/smarty/templates_c';

        $smarty->cache_dir = $dir . '/smarty/cache';

        $smarty->config_dir =$dir . '/smarty/configs';

        $content = implode('', file($dir . "/index.txt"));

        $head = implode('', file($dir . "/head.txt"));

        $footer = implode('', file($dir . "/footer.txt"));

        $navbar = implode('', file($dir . "/navbar.txt"));

        if(preg_match('/<title>(.*?)<\/title>/is', $head, $m)) {

                $title = $m[1];

        } else {

                $title = "Default Title";


        $smarty->assign("title", $title);

        $smarty->assign("head", $head);

        $smarty->assign("footer", $footer);

        $smarty->assign("content", $content);

        $smarty->assign("navbar", $navbar);



Now, for Smarty to operate you need to supply some directories (i.e. template_dir, compile_dir, cache_dir, config_dir). compile_dir and cache_dir need to writeable by the web server user so in Debian something like:



mkdir $DIR/smarty

mkdir $DIR/smarty/cache

mkdir $DIR/smarty/configs

mkdir $DIR/smarty/templates

mkdir $DIR/smarty/templates_c

sudo chown -r :www-data $DIR/smarty/cache

sudo chown -r :www-data $DIR/smarty/templates_c

Write default.tpl into $DIR/smarty/templates/default.tpl . For example,






<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>

<link rel="stylesheet" type="text/css" href="default.css" media="screen"/>




<div class="body">

        <div class="title">{$title}</div>

        <div class="subnav">




        <div class="main">



        <div class="footer">






Now, moving from here would be something like:

   1. Writing code to check for a navbar.txt in the current direction. If not found, stuff navbar Smarty tag with "Back up a level" that moves up one subdirectory (i.e. go to /directory/index.html if you were are /directory/author.html, and go to /index.html when you were are /directory/index.html, etc.)

   2. Could proceed by designing a number of templates in Smarty for the same basic content - i.e. skin-bluesteel.tpl and then providing a user interface to switch templates.

   3. Perhaps eliminate filesystem reliance and put URL's into a database. Map /directory to /directory/index.html, similar with /. If not in database, display a generic 404 error. You can develop this script by calling it like /database-script-were-writing.php/directory/index.html and then looking into PATH_INFO from the server which will contain /directory/index.html . Once you have this perfected, you set up apache with something like "Alias / /var/www-sites.d/malborn.pachogrande.com/database-script-were-writing.php" and everything should pretty much just work.