Fixed #10285 - Added render_comment_list template tag to comments app. Thanks Kyle Fuller for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12082 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2010-01-04 02:29:12 +00:00
parent f6c519e2b9
commit b9d698e9f2
5 changed files with 122 additions and 6 deletions

View file

@ -39,6 +39,18 @@ available in the context, then you can refer to it directly::
{% get_comment_count for entry as comment_count %}
<p>{{ comment_count }} comments have been posted.</p>
Next, we can use the :ttag:`render_comment_list` tag, to render all comments
to the given instance (``entry``) by using the ``comments/list.html`` template.
{% render_comment_list for entry %}
Django will will look for the ``list.html`` under the following directories
(for our example)::
comments/blog/post/list.html
comments/blog/list.html
comments/list.html
To get a list of comments, we make use of the :ttag:`get_comment_list` tag.
This tag's usage is very similar to the :ttag:`get_comment_count` tag. We
need to remember that the :ttag:`get_comment_list` returns a list of comments
@ -58,7 +70,7 @@ display the comments template available under your ``comments/form.html``.
The other method gives you a chance to customize the form.
The first method makes use of the :ttag:`render_comment_form` tag. It's usage
too is similar to the other two tags we have discussed above::
too is similar to the other three tags we have discussed above::
{% render_comment_form for entry %}
@ -74,6 +86,7 @@ tag called :ttag:`comment_form_target`. This tag on rendering gives the URL
where the comment form is posted. Without any :ref:`customization
<ref-contrib-comments-custom>`, :ttag:`comment_form_target` evaluates to
``/comments/post/``. We use this tag in the form's ``action`` attribute.
The :ttag:`get_comment_form` tag renders a ``form`` for a model instance by
creating a context variable. One can iterate over the ``form`` object to
get individual fields. This gives you fine-grain control over the form::

View file

@ -84,11 +84,34 @@ different ways you can specify which object to attach to:
In the above, ``blog.entry`` is the app label and (lower-cased) model
name of the model class.
.. templatetag:: get_comment_list
Displaying comments
-------------------
To display a list of comments, you can use the template tags
:ttag:`render_comment_list` or :ttag:`get_comment_list`.
.. templatetag:: render_comment_list
Quickly rendering a comment list
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The easiest way to display a list of comments for some object is by using
:ttag:`render_comment_list`::
{% render_comment_list for [object] %}
For example::
{% render_comment_list for event %}
This will render comments using a template named ``comments/list.html``, a
default version of which is included with Django.
.. templatetag:: get_comment_list
Rendering a custom comment list
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the list of comments for some object, use :ttag:`get_comment_list`::
{% get_comment_list for [object] as [varname] %}