Monks ~

For years I've created HTML template files and put then in the web server directory, in directories parallel to images, CSS files, and the like. Someone said to me a few days ago, "You know, if you think about it those templates are clearly config files. They shouldn't be served by the web server, and in fact belong somewhere like /var."

"Hmmm..." I thought.

On one hand this makes a lot of sense. The fact that the templates are more HTML than anything strikes me as incidental, a red herring. Jamie's mantra is: "If the file isn't designed to be served by the web server, it doesn't belong in a servable directory." And that's hard to argue with.

On the other hand, how much purity do we need? Lots of little web frameworks keep their template files in the server directory. I want to examine the problem a little more and get soem other perspectives.

Directories like "/var" are root-only, and keeping template files there means they're not editable by regular users. Some web apps are built to be installed and maintained by users in their home directories, and the server would need special setup to accomodate this. Slash installs its templates under "/usr/local", but it's a large framework and depends on the administrators having special permissions.

Configuration is another issue, closely related. What if a user wants to install multiple copies of the application and have each behave or look differently? One template repository is clearly not enough in this situation.

Lastly I worry about correctly configuring web server permissions. Slash gets around this by compiling all its Template templates into a database, so the webserver doesn't have to care where they are on the filesystem. If an application is in a user's home directory but you want to keep the template files away from the webserver, then you're looking at nastiness like http://cgiwrap.unixtools.org.

So here's what I can think of:

It's a good idea to keep templates under the web server's directory if:
  • The application is, or instances thereof are, meant to be installed by users with no special privileges.
  • The overhead for a different solution (e.g. precompiled templates in a database) isn't worth it.
  • The application is designed to run multiple instances, each potentially with different templates.
It's a good idea to keep templates elsewhere on the filesystem, not accessible by the web server, if:
  • There is security-sensitive information in the templates.
  • The templates are for application use only and do not need to be changed by users.
  • The application is very large, already needs to talk to the database a lot, and the templates can be pre-compiled.

But this is just my perspective. What are some other ways of looking at this?


In reply to Where to keep HTML templates for a web application? by legLess

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.