leocharre has asked for the wisdom of the Perl Monks concerning the following question:

I am being handed down responsibility over a site. It has static content.

My goal: for the client to be able to edit their own text content at will- in already existing html pages.

This is a little different from simply seeking a good templating system, there will not be new pages, this is not really a "templating system" problem- which suggests many pages controlled via one template- this is about making static content editable, but keeping it static.

Here's what I've done in the past to solve this task:

I am thinking a good way to start planning for a project (after checking if it's already been done, and well)- is to plan how you want the users (webdesigner) to interact with the software.

Q:As a webmaster, How would I want to allow a client to edit already existing webpages?

A: What's easiest for me. I just want to grab their documents and where it says :

<h1>about us</h1> <p>This is the about us page. Welcome.</p>

I want to open it in vim and make it this:

<h1 class="_EDITABLE_">about us</h1> <p class="_EDITABLE_">This is the about us page. Welcome.</p>

or:

<div class="_EDITABLE_"> <h1>about us</h1> <p>This is the about us page. Welcome.</p> </div>

And let the backend software worry about it from there- Which I may end up coding, again. It's simple if you get your html encoding/char escaping right.

I've solved this kind of thing in the past by simply doing this to the above example:

<!--_START_EDITABLE_--> <h1>about us</h1> <p>This is the about us page. Welcome.</p> <!--_END_EDITABLE_-->

And then my backend software opens the stuff up with js htmlarea, etc, and lets user edit the text area. If no target was defined (by absence of _END_EDITABLE_ or whatever) then the page is inspected for js, if none is fount, then you can edit the whole body tag content. It worked well.

This kind of process has the advantage of keeping all the content in the html document. It would provide a webmaster with this: if you inherit a site, you just add class="YOURHOICE" to any elements you want the client to edit, and voila-done.
The other cool thing is that if you move the site to another host, your content is still valid static html.

HTML Template could possibly fit here.. It has the ability to define a "default" value.. so.. the above example could be turned to this:

<h1> <TMPL_VAR NAME=H1 DEFAULT="about us"> </h1> <p><TMPL_VAR NAME=P1 DEFAULT="This is the about us page. Welcome."></p +>

This is a potential pain in the @55 with multiple paragraphs, etc. Also, if you move the site to another host, not configured, the thing breaks.

Any suggestions about some modules, projects I should be looking at (that fall within my needs)?

Also.. What is a good way to target a html element without violating w3c guidelines? I thought adding a class name was alright, comments defining an excerpt of html might suck, because certain wysiwyg editors change them or take them out, not reliable. I want someone using dreamweaver, notepad, or frontpage (gag) to likely not mess up the target areas defined.

I've takena look at HTML::EasyTemplate, but I'm not sure this is a system via which I would still have valid html- and the content still reside in the document?

Replies are listed 'Best First'.
Re: Making static html documents editable, but still static.
by ww (Archbishop) on Jun 16, 2006 at 20:00 UTC

    /me likes jeffa 's suggestion, but TIMTOWTDI (sketch only):
    build db (mySQL, Oracle, whatever you want) of current content;
    code appropriate query(ies) to plug into your template;
    then give (l)user(s) gui tools to update the db contents.
    awkward? yep.
    more work? yep!
    but if you don't want future grief, keep users away from the html.
    Letting them near it is a lot like letting toddlers play in the street!

Re: Making static html documents editable, but still static.
by CountZero (Bishop) on Jun 16, 2006 at 21:24 UTC
    I would definitely keep the "user-serviceable parts" stored in a database. Allowing users to directly edit static webpages (i.e. files on your server) would need you to implement a locking system to avoid nasty race conditions. Database servers have this service already built-in. You could then write a number of templates for the different types of pages you have and let the server combine the fixed parts of your pages with the user-written parts.

    Checking the user input for potentially dangerous constructs is still necessary, but since the user-written parts are (safely) stored away in a database, you don't have to parse your static files to find the parts which were user written.

    An obvious framework for such a system is IMHO Catalyst.

    On second thought, it is a bit WIKI-like what you are trying to do, so you might wish to look into that.

    On third thought, it is not much different from what we do here at PerlMonks, so perhaps the Everything engine is your best bet.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Making static html documents editable, but still static.
by jeffa (Bishop) on Jun 16, 2006 at 19:18 UTC

    My first thoughts are Krang, but it comes with a very steep learning curve. However, if you can learn the in's and out's it does provide a nice way for people who don't know HTML to produce documents and publish the static pages to the website.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      jeffa, thank you for the suggestion. I am having trouble where Krang could address:

      • Simple conversion of existing html web page to editable parts of the page. for example rounding off half of the html code and letting a user do what they want with it- examples in original post.
      • Keeping the document as a single html document , that is static, and valid. Someone else can edit the doc without knowing anything about Krang,HTML Template, etc etc.

      I want to stress that this is not about a templating system, this is about keeping a static website; static. And offering a way to edit it (via minimal alteration and or appending ).

      If Krang addresses these things, I'm having trouble finding it. I'm sorry if I'm being confusing in what I'm asking about. It's a little weird.. I know.

        Regarding the "simple conversion of existing HTML" part ... well, someone has to have knowledge of HTML in order to do this. With Krang you set up the skeleton of the document and provide objects that render themselves when published while simultaneously providing widgets (input boxes, radio buttons, text areas, etc.) that allow your users (editors) to enter in the content. But someone with a good knowledge of HTML has to set up the page framework, and someone with a good knowledge of Krang sets up the overall object heirarchy and Apache configuration.

        As for "keeping the doc as a single HTML document," when you publish a page in Krang, you have a single, static HTML document. Your editors edit the document via a webpage form that you, the Krang developer create for your editors. It is possible to this without having to have your editors know HTML or HTML::Template, but you will have to jump through many frustrating hoops to accomplish this.

        What it sounds like is that you want to have your cake and eat it too. Rarely is this possible, you have to make compromises. Krang indeed addresses these issues, but you have to do a lot of work to climb that steep learning curve. Since i myself do have a bit of Krang knowledge and experience, i would look into Krang to solve this problem.

        I am of the belief, however, that people who want to make HTML pages should at least learn HTML or be prepared to hire skilled web developers. Would you trust just anybody to work on your car or house? Didn't think so. Why do people insist that the websites should have the ability to be built and maintained by unskilled people? :(

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)
        
Re: Making static html documents editable, but still static.
by Anonymous Monk on Jun 19, 2006 at 19:06 UTC
    Teach your client to use wysiwyg
Re: Making static html documents editable, but still static.
by metaperl (Curate) on Jun 20, 2006 at 16:23 UTC
    HTML::Seamstress was designed for manipulating HTML without being embedded in the HTML. I try to read perlmonks everyday, but it would be better to email me (the author of Seamstress), or join the mailing list if you have any questions regarding it.