Tuesday, December 27, 2011

Re: {% elif %} error

There's no {% elif %}. You'll have to do:

{% if bookmark.hours %}
{{bookmark.hours}} hours ago
{% else %}
   {% if bookmark.days %}
   {{ bookmark.days }} days ago
   {% else %}
      {% if bookmark.months %}
      {{ bookmark.months }} months ago
      {% else %}
       {{ bookmark.years }} years ago
      {% endif %}
   {% endif %}
 {%endif}

(Sorry if I missed any closing {%endif%} - you'll have to balance those). Also, I'd suggest you to do this logic part in the view itself.

On Wed, Dec 28, 2011 at 12:14 PM, Tsung-Hsien <jasoniem9246@gmail.com> wrote:
Hi,
I want to use {% elif %}
my template:
                       {% if bookmark.hours %}
                               {{ bookmark.hours }} hours ago
                       {% elif bookmark.days %}
                               {{ bookmark.days }} days ago
                       {% elif bookmark.months %}
                               {{ bookmark.months }} months ago
                       {% else %}
                                {{ bookmark.years }} years ago
                       {% endif %}


show error:
Invalid block tag: 'elif', expected 'else' or 'endif'

It can work without elif, if use if...else loop.

my django version is 1.31

how to solve this?
thanks!!



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment