Edgewall Software

Ticket #296 (new enhancement)

Opened 6 years ago

Last modified 4 years ago

py:element directive

Reported by: Arc Riley <arcriley@…> Owned by: cmlenz
Priority: minor Milestone: 0.7
Component: Template processing Version: 0.5.1
Keywords: Cc:

Description (last modified by cmlenz) (diff)

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.

Attachments

Change History

  Changed 6 years ago by cmlenz

  • description modified (diff)

(add some formatting to the description)

  Changed 6 years ago by cmlenz

  • description modified (diff)

  Changed 5 years ago by cmlenz

  • milestone changed from 0.5.2 to 0.6

Milestone 0.5.2 deleted

  Changed 5 years ago by cmlenz

  • milestone changed from 0.6 to 0.7

follow-up: ↓ 6   Changed 5 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>

in reply to: ↑ 5   Changed 4 years ago by Carsten Klein <carsten.klein@…>

Replying to Carsten Klein <carsten.klein@…>:

nah, must have been out of my mind.. forget this.

  Changed 4 years ago by Carsten Klein <carsten.klein@…>

see also the initiative to support pluggable directives libraries in WorkInProgress/PluggableDirectivesLibraries and ticket #395 thereof.

Add/Change #296 (py:element directive)

Author


E-mail address and user name can be saved in the Preferences.


Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will change from cmlenz. Next status will be 'new'
The owner will change from cmlenz to anonymous. Next status will be 'assigned'
 
Note: See TracTickets for help on using tickets.