Opened 19 years ago

Closed 19 years ago

Last modified 17 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

Description

What if I has two contexts:

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

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>

or

<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 by Adrian Holovaty, 19 years ago

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