Thank you. Using the counter0 as an index into a list seemed like an
obvious use case to me. So I give your 'get' filter idea a +1.
Thanks for the CSS idea. I found an alternate solution using the <COL
align="left"> tag to set the alignment on a whole column so I only have
to loop thru the align list once. More efficient than what I was trying
to do originally.
Thanks,
Michael
Ned Batchelder wrote:
> The more I think about your questions, the more I think Django could use
> a |get filter that would be similar in spirit to the |slice filter.
> |get would be used to get an attribute or index of an object. Then you
> could use:
>
> <div align='{{ align|get:forloop.counter0 }}'>
>
> This |get filter is something I just made up, so it is not available to
> you, though.
>
> In this case, you can use CSS to achieve what you need:
>
> <style>
> {% for al in align %}
> td.align{{forloop.counter0}}: { text-align: {{al}}'; }
> {% endfor %}
> </style>
> ...
> {% for col in row %}
> <td class="align{{forloop.counter0}}">{{col}}</td>
> {% endfor %}
>
> (I've probably scrambled the proper CSS attributes, you get the idea.)
>
> --Ned.
> http://nedbatchelder.com/blog
>
> Michael Hipp wrote:
>> David Reynolds wrote:
>>
>>> On 3 Feb 2008, at 3:32 pm, Michael Hipp wrote:
>>>
>>>
>>>> Malcolm Tredinnick wrote:
>>>>
>>>>>> Or is there some other way to get at my 'align' list?
>>>>>>
>>>>> Look at the {% cycle %} template tag. It's designed for precisely
>>>>> this
>>>>> purpose.
>>>>>
>>>> Thank you. But can someone show me how to make 'cycle' work?
>>>>
>>>> from django.template import Context, Template
>>>> items = (0, 1, 2, 3, 4, 5)
>>>> mycycle = ("one", "two", "three")
>>>> t = Template("""
>>>> {% for item in items %}
>>>> {% cycle mycycle %}
>>>> {% endfor %}
>>>> """)
>>>> t.render(Context({ "items": items, "mycycle": mycycle }))
>>>>
>>> Put in your template:
>>>
>>> {% for item in items %}
>>> <div class="{% cycle left,right %}>
>>> Some text here
>>> </div>
>>> {% endfor %}
>>>
>>> Then a left and right class in your CSS to do the aligning.
>>>
>>
>> Unless I'm misunderstanding, this is essentially hardcoding the left and
>> right.
>>
>> If I knew beforehand how the columns should be aligned I'd just put it
>> in the html/css. The left and right values can only come from the Python
>> as it ultimately comes from the specific URL requested by the user.
>>
>> How can I supply it values in a list from Python?
>>
>> Thanks,
>> Michael
>>
>>
>>
>>
>
> --
> Ned Batchelder, http://nedbatchelder.com
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---