I am developing a website. On the server side, I use python (and Genshi) to manipulate / generate HTML. But I find that I am manipulating the same kind of client-side HTML snippets using Javascript.
Let me show you an example. Suppose I have an editable list of elements:
<form .... > <ul> <li id="i1">Name: <input type="text" name="i1" value="Item 1" /> <a href="#">[del]</a></li> <li id="i2">Name: <input type="text" name="i2" value="Item 2" /> <a href="#">[del]</a></li> </ul> <a id="addnew" href="#">[new]</a> </form>
Note. The label dynamically adds new elements to the form. It should not (should) make any requests to the server.
Both the server and the client must know this "template" (pseudocode):
<li id="${id}">Name: <input type="text" name="${name}" value="${val} " /> <a href="#">[del]</a></li>
The server must know this in order to create the original HTML list, and the client must know it in order to allow users to add and remove elements using anchors.
What can you say about best practices for improving reuse in a scenario like this?
Some approaches that I already know I would like to avoid:
- Creating a source list using javascript. I am trying to use javascript to improve some parts of user interaction.
- Using a template language that I can somehow reuse between the client and the server is not an option, because I'm stuck with Genshi now
- Creating server side Javascript. Tried this before, and this is a pain for debugging, due to the extra level of indirection
source share