Search code examples
htmlseparation-of-concerns

How to separate design and content in a dynamic website?


In normal case, I can separate the text and the style, but how should I do it, when the text is dynamic (it is editable by the admin user)? The user of course wants to use bold, italic, etc, but if I put a common html-editor (I think) I broke the rule of the separation, because there will be html elements in the text. (I can use BB codes, but it is the same.)
In a long term I think it can cause problems when I want to use the text in any non-html environment. Of course I can strip the html tags, but it is not the way I would like to use (not because it won't work, but the original theoretical issues).
In some cases I can break apart the sentences to solve this problem, but I think it's a bad way, because the parts are pointless alone, and it won't be so easily editable too.

Is there any good solution for this?


Solution

  • That's perfectly ok. You give the user the oppertuniny to set some attributes for the text (BBCodes recomended). That is content. Then it's part of the design to interpret the attributes and style it. For example you may provide the feature to let the user define something like [headline]MyHeadline[/headline]. This is pure content.

    How to replace [headline] with HTML and how to style the resulting text is up to the design.

    Edit: I recommend BBCodes to provide a closed set of features. That may be easier to deal with. You could just use them in another context and interpret them, instead of stripping out HTML.