Package genshi :: Package template :: Module directives :: Class ReplaceDirective |

# Class ReplaceDirective

    object --+
             |
     Directive --+
                 |
                ReplaceDirective

Implementation of the `py:replace` template directive.

This directive replaces the element with the result of evaluating the value of the `py:replace` attribute:

    >>> from genshi.template import MarkupTemplate
    >>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
    ...   <span py:replace="bar">Hello</span>
    ... </div>''')
    >>> print tmpl.generate(bar='Bye')
    <div>
      Bye
    </div>

This directive is equivalent to `py:content` combined with `py:strip`, providing a less verbose way to achieve the same effect:

    >>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
    ...   <span py:content="bar" py:strip="">Hello</span>
    ... </div>''')
    >>> print tmpl.generate(bar='Bye')
    <div>
      Bye
    </div>

Nested Classes
Inherited from `Directive`: `__metaclass__`

Instance Methods
Inherited from `Directive`: `__call__`, `__init__`, `__repr__` Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`

Class Methods
attach(cls, template, stream, value, namespaces, pos) Called after the template stream has been completely parsed. |

Class Variables
| tagname = ``'``replace``'``

Properties
Inherited from `Directive`: `expr` Inherited from `object`: `__class__`

Method Details

### attach(cls, template, stream, value, namespaces, pos) Class Method |
Called after the template stream has been completely parsed. This class method should return a `(directive, stream)` tuple. If `directive` is not `None`, it should be an instance of the Directive class, and gets added to the list of directives applied to the substream at runtime. `stream` is an event stream that replaces the original stream associated with the directive. Parameters: `template` - the Template object `stream` - the event stream associated with the directive `value` - the argument value for the directive; if the directive was specified as an element, this will be an Attrs instance with all specified attributes, otherwise it will be a `unicode` object with just the attribute value `namespaces` - a mapping of namespace URIs to prefixes `pos` - a `(filename, lineno, offset)` tuple describing the location where the directive was found in the source Overrides: Directive.attach (inherited documentation)