Note that there are some explanatory texts on larger screens.

plurals
  1. POReusing HTML between the server and client sides
    primarykey
    data
    text
    <p>I'm developing a web site. On the server-side I'm using python (and Genshi) to manipulate/generate the HTML. But I find myself manipulating <strong>the same</strong> kind of HTML fragments on the client-side, using Javascript.</p> <p>Let me show you an example. Suppose I have an editable list of items:</p> <pre><code>&lt;form .... &gt; &lt;ul&gt; &lt;li id="i1"&gt;Name: &lt;input type="text" name="i1" value="Item 1" /&gt; &lt;a href="#"&gt;[del]&lt;/a&gt;&lt;/li&gt; &lt;li id="i2"&gt;Name: &lt;input type="text" name="i2" value="Item 2" /&gt; &lt;a href="#"&gt;[del]&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;a id="addnew" href="#"&gt;[new]&lt;/a&gt; &lt;/form&gt; </code></pre> <p>Note: The <code>[new]</code> anchor dynamically adds new items to the form. It doesn't (have to) make any request to the server.</p> <p>Both the server and the client have to know this "template" (pseudo-code):</p> <pre><code>&lt;li id="${id}"&gt;Name: &lt;input type="text" name="${name}" value="${val} " /&gt; &lt;a href="#"&gt;[del]&lt;/a&gt;&lt;/li&gt; </code></pre> <p>The server has to know it to create the initial HTML list, and the client has to know it to allow the users to add and remove items, using the anchors.</p> <p><strong>What would you say are the best-practices to improve reuse in a scenario like this?</strong></p> <hr> <p>Some approaches that I already know I'd like to avoid:</p> <ul> <li>Creating the initial list using javascript. I'm trying to use javascript to improve some parts of the user interaction only</li> <li>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 for now</li> <li>Generating Javascript on the server side. Tried this before, and it's a pain to debug, due to the extra level of indirection</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload