Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#476 closed enhancement (wontfix)

use vars values in template {{}} dotted style

Reported by: Sokolov Yura Owned by: adrian
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: UI/UX:

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 Changed 10 years ago by adrian

  • Resolution set to wontfix
  • Status changed from new to closed

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