livepage.xhtml   [plain text]


<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>LivePage</title></head>

<body>

<h1>LivePage</h1>

<div class="note">
<p>
This HOWTO documents the LivePage class, part of the Woven framework. The Woven framework should not be used for new projects. The newer <a href="http://www.divmod.org/Home/Projects/Nevow/">Nevow</a> framework, available as part of the <a href="http://www.divmod.org/Quotient/">Quotient</a> project, is a simpler framework with consistent semantics and better testing and is strongly recommended over Woven.
</p>

<p>
The Woven documentation below is maintained only for users with an existing Woven codebase. The LivePage HOWTO is just a quick bootstrap page in any case.
</p>
</div>

<img title="Overview of LivePage" alt="Overview of LivePage"
src="../img/livepage.png" />

<p>To use LivePage, subclass or instantiate <code class="API"
base="twisted.web.woven.page">LivePage</code> instead of <code class="API"
base="twisted.web.woven.page">Page</code>. Then, in your HTML template, include
the following HTML fragment somewhere towards the bottom of the page:</p>

<pre>
  &lt;span view="webConduitGlue" /&gt;
</pre>

<p>Then, <a href="controllerindepth.xhtml#eventhandlers">Event handlers</a> can forward
client-side JavaScript events to the Server, and you can send JavaScript to the
browser after a page has already loaded. Example:</p>

<pre>
class Foo(page.LivePage):
    template = ('&lt;html&gt;&lt;body&gt;'
                'Nothing here!&lt;span view="webConduitGlue" /&gt;'
		'&lt;/body&gt;&lt;/html&gt;')
    def setUp(self, request):
        global currentPage

        # don't save this in a global but somewhere your code can get
        # to it later
        currentPage = request.getSession(interfaces.IWovenLivePage)

# then later, in response to some server-side event
def fooHappened():
    global currentPage

    currentPage.sendScript("alert('hello, world!')")
</pre>

</body>

</html>