At 8:13 PM on 27 Nov 2009, Octavian Râsnita wrote: > From: "C. Chad Wallace" <cwall...@lodgingcompany.com> > > At 8:45 AM on 26 Nov 2009, Randal L. Schwartz wrote: > > > >>>>> "Octavian" == Octavian Râsnita <orasn...@gmail.com> writes: > > > > Octavian> but if I put just simple html code in the database > > > > ... then your successor will submit your code to thedailywtf.com > > > > ... and we'll all have a good laugh at your expense. > > > > Seriously, wrong way to do it. > > I agree with Randal, wholeheartedly. You need to maintain a > separation between data (in the database) and HTML (in your > templates). They should not be mixed. > > What happens when, for instance, you change your templates to XML > rather than HTML? Or you want to present the same data as a PDF? > It's going to have HTML in it! > > > Well, as I said, I also agree, but I couldn't find that recommended > way. Can you tell me the solution for storing complex documents that > include text, lists, tables, headings which doesn't use HTML?
I use BBCode for that. There is a Template plugin for BBCode, and there are Perl modules (e.g., Parse::BBCode) that convert from BBCode to other formats. However, Markdown or Textile might work, too... They let you write your formatting in plain text, and then translate it up to HTML or whatever you want. But I think the most presentation-agnostic way to do this would be to define the types of documents your users will want to enter, and then have them select a type, and provide different fields (dropdowns, text boxes, etc.) in your UI based on that type. For instance, you could have a 'section' type, with a 'heading' and a 'paragraph' field, or a 'list' type with a 'heading' and multiple 'items'. Then you store just those fields in the database, and when it comes time to present them, you slot the data into the appropriate HTML tags. The latter may be overkill... that's up to you to decide. But I think HTML is the worst choice here, because your users may end up entering some very complex HTML that would be hard to parse out if needed. Also, giving the user HTML often means they can break the rendering of YOUR HTML if the stuff they've entered is broken! I saw that happen *many* times before switching to BBCode... it's embarrassing to say the least! PS, Let's please keep this on-list, for the benefit of everyone. -- C. Chad Wallace, B.Sc. The Lodging Company http://www.skihills.com/ OpenPGP Public Key ID: 0x262208A0
signature.asc
Description: PGP signature
_______________________________________________ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates