List Info

Thread: else tag for ifchanged




else tag for ifchanged
user name
2006-06-28 18:19:43
i am currently looking at building a kinda daily posts blog
thing and
basically i need this functionality.  if the date changes, i
need a
"date" header.  if the date hasn't changed but
i'm on a new blog post i
just need a simple separator.  Now, at first i would imagine
this be
the code:

{% ifchanged %}
<tr><th class="info"
colspan="2"><span
class="date">{{
post.created|date:"Y.m.d"
}}</span></th></tr>
{%else %}
<hr />
{% endifchanged %}

but else is not a valid block tag.  any insight from devs or
other
users.
i am using the django.views.generic.date_based.archive_index
generic
view


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

else tag for ifchanged
user name
2006-06-28 19:50:18
On 6/28/06, dcurtisgmail.com <dcurtisgmail.com> wrote:
>
> i am currently looking at building a kinda daily posts
blog thing and
> basically i need this functionality.  if the date
changes, i need a
> "date" header.  if the date hasn't changed
but i'm on a new blog post i
> just need a simple separator.  Now, at first i would
imagine this be
> the code:
>
try something like this:

{% ifchanged %}
<tr><th class="info"
colspan="2"><span
class="date">{{
post.created|date:"Y.m.d"
}}</span></th></tr>
{% endifchanged %}
{% ifnotchanged %}
<hr />
{% endifnotchanged %}
>
> but else is not a valid block tag.  any insight from
devs or other
> users.
> i am using the
django.views.generic.date_based.archive_index generic
> view
>
>
> >
>


-- 
----
Waylan Limberg
waylangmail.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

else tag for ifchanged
user name
2006-06-29 03:34:01
On 6/28/06, dcurtisgmail.com <dcurtisgmail.com> wrote:
> i am currently looking at building a kinda daily posts
blog thing and
> basically i need this functionality.  if the date
changes, i need a
> "date" header.  if the date hasn't changed
but i'm on a new blog post i
> just need a simple separator.  Now, at first i would
imagine this be
> the code:
>
> {% ifchanged %}
> <tr><th class="info"
colspan="2"><span
class="date">{{
> post.created|date:"Y.m.d"
}}</span></th></tr>
> {%else %}
> <hr />
> {% endifchanged %}
>
> but else is not a valid block tag.  any insight from
devs or other
> users.
> i am using the
django.views.generic.date_based.archive_index generic
> view

Ah, we should add an {% else %} clause to the {% ifchanged
%} tag --
that'd be a nice addition.

For this solution, you could use {% regroup %}. The {%
regroup %} tag
is pretty complex and kind of hard to understand, but it's
powerful
for times like these.

    {% regroup post_list by created as date_list %}

    (Now post_list is a list of objects grouped by distinct
"created" values.
    Each one has a "grouper" and a
"list" attribute.)

    {% for date in date_list %}
    <tr><th class="info"
colspan="2"><span
class="date">
    {{ date.grouper|date:"Y.m.d" }}
    </span></th></tr>
      {% for entry in date.list %}
      {{ entry.headline }} ...whatever
      {% endfor %}
    <hr />
    {% endfor %}

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )