Opened 16 years ago
Last modified 8 years ago
#296 new enhancement
py:element directive
Reported by: | Arc Riley <arcriley@…> | Owned by: | cmlenz |
---|---|---|---|
Priority: | minor | Milestone: | 0.9 |
Component: | Template processing | Version: | 0.5.1 |
Keywords: | Cc: |
Description (last modified by cmlenz)
Currently to generate elements from a list some hackery is needed, ie:
<?python from genshi.builder import tag ?> <py:for each='field in fields'> ${getattr(tag,field)} </py:for>
It would be cleaner if we could instead:
<py:for each='field in fields'> <py:element name="field"/> </py:for>
py:attrs should be applied second such that:
<py:for each='field in fields'> <py:element name='field' py:attrs='fields[field]'/> </py:for>
It would be useful if the element name could contain the namespace, ie:
fields = {'greek:alpha' : {'value' : 1, 'xmlns:greek' = 'xml:foo:greek'}, 'game:monsters' : {'hp' : 552, 'label' : 'Queen Banshee'}}
In XMPP there are many cases where it'd be useful for generated elements to be in different namespaces like this. A separate py:element namespace= attribute may also be useful in some situations but would increase complexity in the above examples.
Change History (8)
comment:1 Changed 16 years ago by cmlenz
- Description modified (diff)
comment:2 Changed 16 years ago by cmlenz
- Description modified (diff)
comment:3 Changed 15 years ago by cmlenz
- Milestone changed from 0.5.2 to 0.6
Milestone 0.5.2 deleted
comment:4 Changed 15 years ago by cmlenz
- Milestone changed from 0.6 to 0.7
comment:5 follow-up: ↓ 6 Changed 15 years ago by Carsten Klein <carsten.klein@…>
I think that your working solution misses something in the likes of:
<?python from genshi.builder import tag ?> <py:for each='field in fields'> ${getattr(tag,field)(**fields[field])} </py:for>
comment:6 in reply to: ↑ 5 Changed 15 years ago by Carsten Klein <carsten.klein@…>
Replying to Carsten Klein <carsten.klein@…>:
nah, must have been out of my mind.. forget this.
comment:7 Changed 15 years ago by Carsten Klein <carsten.klein@…>
see also the initiative to support pluggable directives libraries in WorkInProgress/PluggableDirectivesLibraries and ticket #395 thereof.
comment:8 Changed 8 years ago by hodgestar
- Milestone changed from 0.7 to 0.9
Moved to milestone 0.9.
(add some formatting to the description)