Use Macros ========== These macros will help you to generate Fomantic-markup codes quickly and easily. render_ui_nav_item() -------------------- Render a Fomantic nav item. Example ~~~~~~~~ .. code-block:: jinja {% from 'fomantic/nav.html' import render_ui_nav_item %} API ~~~~ .. py:function:: render_ui_nav_item(endpoint, text, iname, color=None, **kwargs) :param endpoint: The endpoint used to generate ``URL``. :param text: The text that will displayed on the item. :param iname: The icon name. :param color: Default: ``None``. :param kwargs: Additional keyword arguments pass to ``url_for()``. render_ui_breadcrumb_item() ---------------------------- Render a Fomantic UI breadcrumb item. Example ~~~~~~~~ .. code-block:: jinja {% from 'fomantic/nav.html' import render_ui_breadcrumb_item %} API ~~~~ .. py:function:: render_ui_breadcrumb_item(endpoint, text, icon='right chevron', **kwargs) :param endpoint: The endpoint used to generate ``URL``. :param text: The text that will displayed on the item. :param icon: Te icon name. Default: ``right chevron``. :param kwargs: Additional keyword arguments pass to ``url_for()``. render_ui_field() ----------------- Render a form input for form field created by `Flask-WTF/WTForms `_. Example ~~~~~~~~ .. code-block:: jinja {% from 'fomantic/form_ui.html' import render_ui_field %}
{{ form.csrf_token() }} {{ render_ui_field(form.username) }} {{ render_ui_field(form.password) }} {{ render_ui_field(form.submit) }}
You can pass extra keyword arguements like ``class`` or ``placeholder`` for each HTML element. Notice that a ``placeholder`` is only allowed by `W3C validation `_ when the input type is ``email``, ``number``, ``password``, ``search``, ``tel``, ``text`` or ``url``. However, it is possible to use a placeholder for input types such as ``datetime``. .. code-block:: jinja {% from 'fomantic/form_ui.html' import render_ui_field %}
{{ form.csrf_token() }} {{ render_ui_field(form.username, class='myClass') }} {{ render_ui_field(form.password, placeholder='Your Password') }} {{ render_ui_field(form.submit) }}
Notice the ``class`` value here will overwrite the ``render_kw={'class': '...'}`` you defined in the form class. Flask-FomanticUI will combine the class value you passed with the ``class`` key of the ``render_kw`` dict or the ``class`` keyword argments with Fomantic classes. API ~~~~ .. py:function:: render_ui_field(field,\ form_type="basic",\ inverted=None,\ horizontal_columns=('sixteen', 'sixteen', 'sixteen'),\ button_style="",\ button_size="",\ button_map={}) :param field: The form field (attribute) to render. :param form_type: Can be ``inline``. See the Fomantic docs for details on different form layouts. :param inverted: If ``True``, define a `inverted `_ form class. Default to ``None``. :param horizontal_columns: *TODO in new relases:* (When using the horizontal layout, layout forms like this. Must be a 3-tuple of ``(column-wide-mobile, column-wide-tablet, column-wide-computer)``). :param button_style: Set button style for ``SubmitField``. Accept `Fomantic UI button style `_ name (i.e. primary, secondary, positive, negative, etc.). Default to ``primary`` (e.g. ``ui primary``). This will overwrite config ``FOMANTIC_BUTTON_STYLE``. :param button_size: Set button size for ``SubmitField``. Accept Fomantic UI button. size name: ``mini``, ``tiny``, ``small``, ``medium``, ``large``, ``big``, ``huge``, ``massive``. Default to ``""`` and this will overwrite config ``FOMANTIC_BUTTON_SIZE``. :param button_map: It given by ``button_map.get(field.name, button_style)``. See :ref:`button_customization` to learn how to customize form buttons. .. tip:: See :ref:`button_customization` to learn how to customize form buttons. render_ui_form() ---------------- Render a complete form element for form object created by Flask-WTF/WTForms. Example ~~~~~~~~ .. code-block:: jinja {% from 'fomantic/form_ui.html' import render_ui_form %} {{ render_ui_form(form) }} API ~~~~ .. py:function:: render_ui_form(form,\ action="",\ method="post",\ inverted=None,\ extra_classes=None,\ color_title=None,\ role="form",\ form_type="basic",\ horizontal_columns=('sixteen', 'sixteen', 'sixteen'),\ enctype=None,\ button_map={},\ button_style="",\ button_size="",\ id="",\ novalidate=False,\ render_kw={},\ form_title=None) :param form: The form to output. :param action: The URL to receive form data. :param method: ``
`` method attribute. :param inverted: If ``True``, define a `inverted `_ form class. Default to ``None``. :param extra_classes: The classes to add to the ````. :param color_title: The color to add to the ```` title. Default to ``None``. :param role: ```` role attribute. :param form_type: One of ``inline``. See the Fomantic docs for details on different form layouts. :param horizontal_columns: When using the horizontal layout, layout forms like this. Must be a 3-tuple of ``('sixteen', 'sixteen', 'sixteen')``. :param enctype: ```` enctype attribute. If ``None``, will automatically be set to ``multipart/form-data`` if a :class:`~wtforms.fields.FileField` or :class:`~wtforms.fields.MultipleFileField` is present in the form. :param button_map: A dictionary, mapping button field name to `Fomantic UI button style `_ names. For example, ``{'submit': 'positive'}``. This will overwrite ``button_style`` and ``FOMANTIC_BUTTON_STYLE``. :param button_style: Set button style for ``SubmitField``. Accept Fomantic UI button style name (i.e. primary, secondary, positive, negative, etc.), default to ``primary`` (e.g. ``ui primary``). This will overwrite config ``FOMANTIC_BUTTON_STYLE``. :param button_size: Set button size for ``SubmitField``. Accept `Fomantic button size `_ name: mini, tiny, small, medium, large, big, huge, massive. Default to ``""`` and this will overwrite config ``FOMANTIC_BUTTON_SIZE``. :param id: The ```` id attribute. :param novalidate: Flag that decide whether add ``novalidate`` attribute in ````. :param render_kw: A dictionary, specifying custom attributes for the ````. :param form_title: The title for the form. .. tip:: See :ref:`button_customization` to learn how to customize form buttons. render_ui_hidden_errors() ------------------------- Render error messages for hidden form field (``wtforms.HiddenField``). Example ~~~~~~~~ .. code-block:: jinja {% from 'fomantic/form_ui.html' import render_ui_field, render_ui_hidden_errors %} {{ form.hidden_tag() }} {{ render_ui_field(form.username) }} {{ render_ui_field(form.password) }} {{ render_ui_field(form.submit) }} {{ render_ui_hidden_errors(form) }} API ~~~~ .. py:function:: render_ui_hidden_errors(form) :param form: Form whose errors should be rendered. render_ui_field_row() --------------------- Render a row of a grid form with the given fields. Example ~~~~~~~~ .. code-block:: jinja {% from 'fomantic/form_ui.html' import render_ui_field_row %}
{{ form.csrf_token }} {{ render_ui_field_row([form.username, form.password]) }} {{ render_ui_field(form.submit) }} {{ render_ui_field(form.remember) }}
is equivalent to .. code-block:: jinja {% from 'fomantic/form_ui.html' import render_ui_field %}
{{ form.csrf_token() }}
{{ render_ui_field(form.username) }} {{ render_ui_field(form.password) }}
{{ render_ui_field(form.submit) }} {{ render_ui_field(form.remember) }}
API ~~~~ .. py:function:: render_ui_field_row(fields,\ row_class={"number":[\ "one",\ "two",\ "three",\ "four",\ "five",\ "six",\ "seven",\ "eight",\ "nine",\ "ten"\ ]\ }) :param fields: An iterable of fields to render in a row. :param row_class: A dictionary, mapping the number of fields to a class definition that should be applied to the div column that contains the fields number. For example: ``
...
``. render_ui_pager() ----------------- Render a simple pager for query pagination object created by Flask-SQLAlchemy. Example ~~~~~~~~ .. code-block:: jinja {% from 'fomantic/pagination.html' import render_ui_pager %} {{ render_ui_pager(pagination) }} API ~~~~ .. py:function:: render_ui_pager(pagination,\ fragment='',\ prev='left chevron',\ next='right chevron',\ extra_classes=None,\ color_active_item=None,\ **kwargs) :param pagination: :class:`~flask_sqlalchemy.Pagination` instance. :param fragment: Add URL fragment into link, such as ``#comment``. :param prev: Icon to use for the "previous page" button. Default: ``'left chevron'``. :param next: Icon to use for the "next page" button. Default: ``'right chevron'``. :param extra_classes: The classes to add to the pagination menu. Can be ``'inverted'``. Default to ``None``. :param color_active_item: Can be ``"red"``, ``"orange"``, ``"yellow"``, ``"olive"``, ``"green"``, ``"teal"``, ``"blue"``, ``"violet"``, ``"purple"``, ``"pink"``, ``"brown"``, ``"grey"``, ``"black"``. Default: ``None``. :param kwargs: Additional arguments passed to ``url_for``. render_ui_pagination() ---------------------- Render a standard pagination for query pagination object created by Flask-SQLAlchemy. Example ~~~~~~~~ .. code-block:: jinja {% from 'fomantic/pagination.html' import render_ui_pagination %} {{ render_ui_pagination(pagination) }} API ~~~~ .. py:function:: render_ui_pagination(pagination,\ endpoint=None,\ prev='left chevron',\ next='right chevron',\ ellipses='…',\ args={},\ fragment='',\ extra_classes=None,\ color_active_item=None) :param pagination: :class:`~flask_sqlalchemy.Pagination` instance. :param endpoint: Which endpoint to call when a page number is clicked. :func:`~flask.url_for` will be called with the given endpoint and a single parameter, ``page``. If ``None``, uses the requests current endpoint. :param prev: Icon to use for the "previous page" button. If ``None``, the button will be hidden. :param next: Icon to use for the "next page" button. If ``None``, the button will be hidden. :param ellipses: Symbol/text to use to indicate that pages have been skipped. If ``None``, no indicator will be printed. :param args: Additional arguments passed to :func:`~flask.url_for`. If ``endpoint`` is ``None``, uses :attr:`~flask.Request.args` and :attr:`~flask.Request.view_args` :param fragment: Add URL fragment into link, such as ``#comment``. :param extra_classes: The classes to add to the pagination menu. Can be ``'inverted'``. Default to ``None``. :param color_active_item: The color classes to add to the pagination item. Default to ``None``. render_static() ---------------- Render a resource reference code (i.e. ````, ``