RE: [SMARTY] Dreamweaver Users - How do you manage sites?

"Jonathan Chum" <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <[email protected]>
Hi Guys,

I had the same problem and thought about doing a symlink just like you
described below. The only problem was that I develop software that may need
to run on other servers where there might not be a telnet interface to
create a symlink. So, what I did was a write a postfilter function for
Smarty that rewrites all the URLs in the HTML template to point to any
location.

In Dreamweaver MX, I use relative pathing from the site root. So everything
points to /templates/images/etc/

Since my Smarty scripts are in a directory above the templates folder, I run
this postfilter function which rewrites most of the common paths for a
href=", img src=", css, and JS alright. I'm sure someone could probably
write a more complete search/replace for all the combinations. 

$sm->register_postfilter(array(TemplateManager, 'change_path'));	

	function change_path($tpl_source, &$smarty)
	{
		$url = "/presencegiftshop";
			
		$search = array(	"=\"/", 	"='/",
"location=/", 		"'/"	);
		$replace = array(	"=\"$url/", "='$url/",
"location='$url/",	"'$url/");					 
	
		return str_replace($search,$replace,$tpl_source);
	}

As for header/footer was concern, I merge the header/footer into one file
which I called main.htm. I have written an extension to Smarty which I call
the TemplateManager which allows me to call a function like:

$sm->Display('index');

What this would do is perform a Smarty fetch on the file index.htm, parse
it, return it back into a string, assign it to the variable 'body', and then
display main.htm. main.htm would have a variable called 'body' which the
contents of index.htm would be replaced into it.

Sometimes, my templates are organic which means if I chop an enclosed table
into a header/footer, it's tough tweaking it without munging it back
together in a temporary HTML document. Having a file main.htm that is my
wrapper built around a variable called 'body' allows me to tweak the
header/footer without chopping it up later.

So my site structure ends up looking like this:

~jchum/index.php				<- Instantiates a copy of
DBManager and TemplateManager

~jchum/libs					<- All of my libs lives here
~jchum/libs/dbi
~jchum/libs/phpmailer
~jchum/libs/smarty
~jchum/libs/TemplateManager.php
~jchum/libs/DBManager.php

~jchum/templates
~jchum/templates/images
~jchum/templates/js
~jchum/templates/css
~jchum/templates/main.htm
~jchum/templates/index.htm

The templates folder contained all of my assets. The main.htm was my
template wrapper which wraps around any other template. I also used .htm
extension instead of .tpl because I could load into Dreamweaver MX much more
easily. I also change the left/right delimiters to use <!--- ---> such that
the Smarty tags appears as comments instead of text in design view.

This setup made it easy for me to drop this package each time I begin
working on a new project. I change the DB connection settings in
DBManager.php, edit the path for the asset rewrites, and I'm ready to rock
and roll :)


-----Original Message-----
From: Gary Smith [mailto:[email protected]] 
Sent: Thursday, August 04, 2005 6:11 PM
To: [email protected]
Subject: Re: [SMARTY] Dreamweaver Users - How do you manage sites?

Aloha All,

Thanks to everyone for their replies. Here is what I ended up doing.

~\htdocs                <- Apache's document root
~\htdocs\index.html     <- This is PHP
~\htdocs\assets\images  <- This is where I put images
~\htdocs\assets\css\    <- This is where I put stylesheets
~\htdocs\assets\js\     <- This is where I put javascript

~\templates             <- Dreamweaver's document root
~\templates\index.tpl   <- This is my smarty template
~\templates\assets      <- Symlink to ~\htdocs\assets

I configure my testing server to parse .tpl files as SSI. Then I use SSI
includes in my templates for template pieces such as header.tpl and
footer.tpl. I then use ftp to upload my files to the remote server.

Great combination!

Gary


in article 231b01c59429$4bfd0410$1fc70005@mark, "Mark Rogers" at
[email protected] wrote on 7/29/05 12:35 AM:

> Gary Smith wrote:
>> What if I move my templates to a folder inside web root? How would I
>> preview them locally and remote?
> 
> For what its worth, this is how I've handled similar situations:
> 
> ~\htdocs                <- Apache's document root
> ~\htdocs\index.php      <- This is PHP
> ~\templates             <- Dreamweaver's document root
> ~\templates\index.html  <- This is HTML template
> ~\templates\img\        <- This is where I put images
> ~\templates\css\        <- This is where I put stylesheets
> ~\templates\js\         <- This is where I put javascript
> 
> (~ is just some directory on my web server under which all the site's
files
> are stored.)
> 
> This means that using ~\templates as the document root the templates work
> fine in (eg) Dreamweaver - image paths etc are fine.
> 
> I then use aliases in the Apache config to map /img/ to ~\templates\img\,
> etc, so that the site works when the PHP code is run (from Apache's
document
> root of ~\htdocs).
> 
> Advantages: All the design stuff is separate from the code logic, so the
> designer has complete control over the ~\templates directory. But it is
all
> outside document root, except for the specific img/js/css stuff which is
> mapped back inside document root by Apache.
> 
> On the occasions where I need dynamic css/js/img files (eg a stylesheet
> which is generated through PHP and likely also through Smarty) I create
> additional directories:
> 
> ~\htdocs\dyncss        <- Dynamic CSS (ie PHP code)
> ~\templates\dyncss     <- Templates for dynamic CSS
> 
> .. etc. Therefore again there is separation between the work of the coder
> and the designer.
> 
> A general point: be VERY careful if you move your templates under document
> root (by which I really mean don't do it).
> 
> Consider:
>   ~\htdocs\index.php
>   ~\htdocs\templates\index.tpl
> 
> It's obvious what http://example.com/index.php will show (ie your webpage,
> presumably based on the index.tpl tenplate), but you must also recognise
> that http://example.com/templates/index.tpl will allow the site visitor to
> see your raw (unprocessed by Smarty or PHP) template code, which may well
> include things you do not want made available. You can fix this through
> appropriate Apache configuration, but in my view it's safer to avoid
> altogether.
> 
> [If you use a Linux/Unix server, as I do, then of-course all the \'s
should
> be /'s. However I think it's easier to distinguish between the file
> structure and the URL's when they're written this way.]
> 
> Mark Rogers,
> More Solutions Ltd

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.