RE: Basic Question: Best practices of site building.
| From: | Anders Janson | Date: | Wed, 21 Nov 2001 10:01:55 +0000 |
| Subject: | RE: Basic Question: Best practices of site building. | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-1998@lists.php.net to get a copy of this message | ||
LIMBOURG Arnaud wrote:
> Hello,
>
> Jason has a nice way to do that. I'll try to explain and Jason can flame me
> if i'm wrong ;))
Well, who is "Jason"?
I wrote that code, so I guess you mean me ;-)
>
>
> I'll just copy and paste here ;)))))))
Did you get the author's permission to publish parts of a private email,
huh????
My lawyers will contact you tomorrow. ;-)
Not... :)
>
> -------------------------------------------------------
> $module = get_module_name_from_somewhere(); // From the DB, likely
> include "$module.php";
> $module_object = new $module;
> $html = $module_object->get_HTML();
>
> $layout = new Smarty;
> $layout->assign('PLACEHOLDER', $html);
> $layout->display('layout.tpl');
> -------------------------------------------------------
This might be a good answer, but does it really fit this question?
It is one way of solving the problem "how do I put output from code/other
template into my main template".
I don't think this will answer the "how do I structure my site with templates"
question.
>
> > Redirect all requests through one file (as per
> > <|~ù«Ÿ':2y±
> > Ýhttp://phpbuilder.com/columns/tim20000526.php3?print_mode=1> or
> >
> > <http://phpbuilder.com/annotate/message.php3?id=1006517>)
> > Advantages:
> > - only one/a small number of pages to maintain
> > Disadvantages:
> > - less control
> > - looks messy (the extra directory needed)
This is what I would suggest (in one way or another). You would basically
design a site with a few reusable layouts = the templates.
The contents stored in separate files or a DB should be formatted through
these few templates, and it would be wise to keep it all in one place.
Less control? Hmmm, depends on how you organize your material, I'd say. I put
articles (or 'pages' ) in a DB, and I put meta tags, page title and so on in
fields separated from the body text. Everything is poured into the template
and comes out just as any other handmade HTML.
And that extra directory? I'm not sure about what you mean. You could do
something like "sitename.com/page/whatever" instead of
"sitename.com/page.php?id=whatever", and IMHO this looks much better :)
>
> >
> > Have separate PHP pages for each existing page.
> > Advantages:
> > - full control over each page
> > Disadvantages:
> > - many files to maintain & edit.
> > - too much repetition of code
This would be easiest, but it could become a maintenance nightmare if the site
grows or you need to redesign it.
Avoid this, unless your site is small.
>
> >
> > Some other method which I cannot think of.
Yeah, some hybrid solution with a mix of separate PHP pages, and some one-file
solutions.
Keep separate PHP files where the everything-through-one-file solution is not
flexible enough, or (obviously) where you have functionality and not just
contents. Lots of similar static pages (contents only) should go through the
centralized handler.
This solution is used by many portals. And this is what I do myself.
>
> >
> > Some of you must have worked out a decent way of doing this,
> > so I'm looking
> > forward to hearing it ;-)
> >
> > Also, how do you treat custom content on the side-menus which
> > appears on
> > certain pages? For example, in the documentation section I
> > need to have
> > the chapter listing in the side-bar (the darker bar on the
> > left-side of
> > each page). I don't want to make a separate header.tpl for
> > this section,
> > as that's one more file to have to update. In other places
> > on the site
> > I'll also need a custom side-bar. Any suggestions?
Ah, perhaps this is where that cut-n-paste code would be useful!? ;-)
Still, it was only hypothetical fragments from hypothetical code, only showing
the principles of a solution I use.
/Anders