Dynamically generating a list of events
I'm assuming from looking the code you're using Zend Framework. I've solved similar issues in Zend and Symfony using php partials.

You could create a partial _list_item.phtml

&lt;li class="ui-content"&gt;
    &lt;div style="float: left; width: 200px;"&gt;
        &lt;span class="ui-icon ui-icon-trash ui-button ui-state-active" style="float: left; margin:3px;"&gt;&lt;/span&gt;
        &lt;input name="dates[]" class="datebox" style="width: 120px;" type="text" value="&lt;?php echo $date ?&gt;" /&gt;
    &lt;/div&gt;
    &lt;div style="padding-left: 200px;"&gt;
        &lt;input name="contents[]" type="text" value="&lt;?php echo $message ?&gt;" style="width: 100%;" /&gt;
    &lt;/div&gt;
&lt;/li&gt;


Then in your view:

&lt;?php foreach ($this-&gt;events as $event): ?&gt;
    &lt;?php echo $this-&gt;partial('list_item.phtml', array(
        'date' =&gt; $event-&gt;GetDate()-&gt;format('Y-m-d'),
        'message' =&gt; $event-&gt;GetMessage(),
    )); ?&gt;
&lt;?php endforeach; ?&gt;


Then for your javascript:

function AddNewEvent()
{
    var today, html, temp;
    // call str_replace because javascript doesn't like new lines in strings
    html = '&lt;?php echo str_replace(PHP_EOL, "\n", $this-&gt;partial('list_item.phtml', array(
        'date' =&gt; $event-&gt;GetDate()-&gt;format('Y-m-d'),
        'message' =&gt; '',
    ))); ?&gt;';
    $(this).after(html);
    temp = $(this).next();
    CreateDateboxes($('.datebox', temp));
    $('.ui-icon-trash', temp).click(RemoveParent);
}


Viola! No template duplication because the affected code is in a partial. No excess javscript templating libraries, although if this kind of thing is prevalent in your application I'd suggest some refactoring and implementing such a templating library.

This approach will have the least impact on your work flow, little to no learning curve, and a short investment in development time for big decrease duplication (bosses love hearing that kind of thing).