Ive just started with jinja.

How can I call a macro if I have its name in a string variable?

The application is that I want to call one of a set of alternative
macros to render html fields where the name of the macro is determined
at runtime.

I can of course do this from python, but how can I do it from within a
template?
Ive been trying to use __dict__ and getattr() without success.

{% macro userField(fDef, field) %}
        <label for="${field.id}">{{fDef.label}}</label>
        <p class="helpText">{{fDef.help}}</p>
        {$ set tName = fDef.type.__name__ %}  {# this gives the macro name I
want #}

        {# want to do something like this here to call the appropriate macro
#}
        {{ self.__dict__[tName](field) }}

{% endmacro %}

{% macro TextNode(field) %}
        <input type="text" id="{{field.id}}" name="{{field.id}}"
value="{{field.value}}" />
{% endmacro %}

{% macro RichTextNode(field) %}
        <div contenteditable id="{{field.id}}" name="{{field.id}}" "
>{{field.value}}</div>
{% endmacro %}

{# more field types not shown #}

-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pocoo-libs?hl=en.

Reply via email to