hi there,
i m trying to make the result of a template tag dependent from another template tag. the use case is the following. i have a headers list which contains all the columns i want to show in a table + the column of the model they are showing +whether they are visible or not.
LIST_HEADERS = (
('Title', 'title', True),
('First Name', 'first_name', True),
('Last Name', 'last_name', True),
('Modified At', 'modified', False),
)
now i have a templatetag which prints out all the headers. consequently i wanted to create a template tag which prints out the body of the table. therefore i want to take the headers list and check which header is visible and want to accordingly show or hide my value.
therefore i created the templatetag template below:
<tr class="{% cycle odd,even %}">
{% for header in headers %}
{% if header.visible %}
<td><a href="{{ model_instance.get_absolute_url|escape }}">{{ model_instance.title }}</a></td>
{% else %}
<td style="visibility:hidden;"><a href="{{ model_instance.get_absolute_url|escape }}">{{ model_instance.title }}</a></td>
{% endif %}
{% endfor %}
</tr>
you see the value {{ model_instance.title }} there. this value i want to change to model_instance.title, model_instance.first_name, model_instance.last_name, ... at runtime.
thus i m searching a way how i can combine {{ model_instance }} with header.model_column .
model_column equals to the second entry in the LIST_HEADERS. Thus model_column would be title, first_name,..
thus the solution would be something like [pseudocode] {{ model_instance.header.model_column }} [pseudocode]
..thus i search a way how i can combine a django template method call with a django template tag attribute..huh.. sounds crazy :D
i hope i explained it good enough! probably there is a much easier solution to my problem. but this seems to me pretty generic and easy and would work.