Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#476 closed enhancement (wontfix)

use vars values in template {{}} dotted style

Reported by: Sokolov Yura Owned by: Adrian Holovaty
Component: Template system Version: 1.1
Severity: normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


What if I has two contexts:

s1= Context({'person':
    {'first_name':'Homer', 'last_name':'Sympson'},
s2= Context({'person':
    {'first_name':'Homer', 'last_name':'Sympson'},

and wish to render template accordinary to field ord?
I wrote a tag to get a dictionary value, but I think it is ugly to write a tag when I want to take variable's field.
May be better to make this possible:

<h4>{{ first_field }}</h4><h3>{{ person.$first_field}}</h3>
<h4>{{ second_field }}</h4><h3>{{ person.$second_field}}</h3>

or even:

<h4>{{ first_field }}</h4><h3>{{ person.${first_field} }}</h3>
<h4>{{ second_field }}</h4><h3>{{ person.${second_field} }}</h3>


<h4>{{ first_field }}</h4><h3>{{ person.(first_field) }}</h3>
<h4>{{ second_field }}</h4><h3>{{ person.(second_field) }}</h3>

or append to resolution order as a last resort: foo[Context[bar]] But it is error prone cause of nested resolution:
person.(fields.(num)) could not be written without braces. Or maybe allow filters to access Context Object as Node.render do,
then most tags could be implemented as filters and this task would be written simpler.

Priority is low cause there are a bit of real life needs. But thinking that it can be possible makes me good.
May be it will help to write custom form generator.

Change History (1)

comment:1 Changed 13 years ago by Adrian Holovaty

Resolution: wontfix
Status: newclosed

This is out of the scope of the template system. Feel free to write (and distribute) your own solutions to this problem, but it's not something I see the core template system supporting.

Note: See TracTickets for help on using tickets.
Back to Top