diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-07-25 16:18:21 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-07-25 16:18:21 +0000 |
| commit | f6dd1a0b498be0de3e33b4a9663a601e4925d210 (patch) | |
| tree | 439e6331c65c5662578a3926fac4c9b529c32181 /docs | |
| parent | 992ef769cbbcb7a47b53d299e551b70d80e993b9 (diff) | |
| download | pyramid-f6dd1a0b498be0de3e33b4a9663a601e4925d210.tar.gz pyramid-f6dd1a0b498be0de3e33b4a9663a601e4925d210.tar.bz2 pyramid-f6dd1a0b498be0de3e33b4a9663a601e4925d210.zip | |
Tweaks via interactive testing.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/tutorials/lxmlgraph/step02.rst | 3 | ||||
| -rw-r--r-- | docs/tutorials/lxmlgraph/step02/myapp/samplemodel.xml | 2 | ||||
| -rw-r--r-- | docs/tutorials/lxmlgraph/step03.rst | 47 | ||||
| -rw-r--r-- | docs/tutorials/lxmlgraph/step03/myapp/samplemodel.xml | 2 |
4 files changed, 38 insertions, 16 deletions
diff --git a/docs/tutorials/lxmlgraph/step02.rst b/docs/tutorials/lxmlgraph/step02.rst index a2c24b7a6..94aca07e4 100644 --- a/docs/tutorials/lxmlgraph/step02.rst +++ b/docs/tutorials/lxmlgraph/step02.rst @@ -35,7 +35,8 @@ your package: :language: xml #. Line 2 provides the root of the model as an XML ``<site>`` node. - The element name doesn't have to be ``<site>``. + The element name doesn't have to be ``<site>``. It has a name of + ``site``. #. In lines 3-4, the ``<site>`` contains 2 top-level children: a and b. These are provided as an element name ``<document>``. This, diff --git a/docs/tutorials/lxmlgraph/step02/myapp/samplemodel.xml b/docs/tutorials/lxmlgraph/step02/myapp/samplemodel.xml index 83678e5e9..bbe474c63 100644 --- a/docs/tutorials/lxmlgraph/step02/myapp/samplemodel.xml +++ b/docs/tutorials/lxmlgraph/step02/myapp/samplemodel.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<site> +<site name="site"> <document name="a"/> <document name="b"/> </site> diff --git a/docs/tutorials/lxmlgraph/step03.rst b/docs/tutorials/lxmlgraph/step03.rst index 89e62f640..5e7911889 100644 --- a/docs/tutorials/lxmlgraph/step03.rst +++ b/docs/tutorials/lxmlgraph/step03.rst @@ -16,19 +16,29 @@ ZPT Templates ======================== Let's start with a ZPT-based default view for the nodes in the XML. -Add this to your project's ``configure.zcml``: +Change your project's ``configure.zcml`` so that it looks like this: .. code-block:: xml - <bfg:view - for=".models.IMyModel" - view=".views.zpt_view" - /> + <configure xmlns="http://namespaces.zope.org/zope" + xmlns:bfg="http://namespaces.repoze.org/bfg" + i18n_domain="repoze.bfg"> -This view stanza indicates that the *default view* for a model that -implements ``lxmlgraph.models.IMyModel`` should be the -``lxmlgraph.views.zpt_view`` function. It is the *default* view because -this stanza does not have a ``name`` attribute. + <!-- this must be included for the view declarations to work --> + <include package="repoze.bfg" /> + + <bfg:view + for=".models.IMyModel" + view=".views.zpt_view" + /> + + </configure> + +In other words, replace the default view function with +``.views.zpt_view``. This view stanza indicates that the *default +view* for a model that implements ``lxmlgraph.models.IMyModel`` should +be the ``lxmlgraph.views.zpt_view`` function. It is the *default* +view because this stanza does not have a ``name`` attribute. Additonally, add a template to your project's ``templates`` directory named ``default.pt`` with this content: @@ -97,9 +107,16 @@ following:: The node has a tag name of: document. +If you visit ``http://localhost:5432/`` you will see:: + + My template is viewing item: site + + The node has a tag name of: site. + We've successfully rendered a view that uses a template against a model using the ZPT templating language. + XSLT Templates ==================== @@ -153,7 +170,8 @@ to your ``views.py`` file: ``xsltview.xsl`` -------------------------------- -How different does the XSLT itself look? At this stage, not too different: +Add a file named ``xsltview.xsl`` to your application's ``templates`` +directory and give it the following contents: .. literalinclude:: step03/myapp/templates/xsltview.xsl :linenos: @@ -176,9 +194,8 @@ How different does the XSLT itself look? At this stage, not too different: Viewing the XSLT -------------------- -With this in place, runnning the application provides a URL such as -``http://localhost:5432/a/xsltview.html``. Going to that URL should -show:: +With those changes in place, restart the application. Visiting to the +``http://localhost:5432/a/xsltview.html`` URL should show:: My template is viewing item: a @@ -186,3 +203,7 @@ show:: We've successfully run an XSL template against our model object. +We've now seen how to use ZPT and XSL templates against model objects +created via an XML tree. + + diff --git a/docs/tutorials/lxmlgraph/step03/myapp/samplemodel.xml b/docs/tutorials/lxmlgraph/step03/myapp/samplemodel.xml index 83678e5e9..bbe474c63 100644 --- a/docs/tutorials/lxmlgraph/step03/myapp/samplemodel.xml +++ b/docs/tutorials/lxmlgraph/step03/myapp/samplemodel.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<site> +<site name="site"> <document name="a"/> <document name="b"/> </site> |
