def widget_type(field):
    """Determine a field's widget type on the fly.
    :rtype: str
    Example:
    .. code::
        {% if field|widget_type == "Textarea" %}
            ...
        {% endif %}
    """

    try:
        return field.field.widget.__class__.__name__
    except AttributeError:
        return field.widget.__class__.__name__