django-templates-macros


Namedjango-templates-macros JSON
Version 0.3 PyPI version JSON
download
home_pagehttps://github.com/twidi/django-templates-macros
SummaryAdd macros to your django templates
upload_time2023-08-16 23:31:53
maintainer
docs_urlNone
authorStephane "Twidi" Angel
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            |PyPI Version|

django-templates-macros
=======================

Add macros to your django templates

------
Origin
------

The original code of this app is taken from https://djangosnippets.org/snippets/2892/ by MattP.

This snippets cites::

    Based on snippet by
        Michal Ludvig <michal@logix.cz> http://www.logix.cz/michal
        http://djangosnippets.org/snippets/363/

    Extended for args and kwargs into templatetags/kwacro.py by
        Skylar Saveland <michal@logix.cz> http://skyl.org
        https://gist.github.com/skyl/1715202

    Modified to support rendering into context by matt@peloquin.com


-----
Where
-----

You can find this package here:

- Github repository: https://github.com/twidi/django-templates-macros
- Pypi package: https://pypi.python.org/pypi/django-templates-macros


-----
Usage
-----

0) Add this app "macros" to your INSTALLED_APPS

1) In your template load the library::

    {% load macros %}

2) Define a new macro called 'my_macro' that takes args and/or kwargs
   All will be optional::

    {% macro my_macro arg1 arg2 baz="Default baz" %}
        {% firstof arg1 "default_arg1" %}
        {% if arg2 %}{{ arg2 }}{% else %}default_arg2{% endif %}
        {{ baz }}
    {% endmacro %}

3) Use the macro with string parameters or context variables::

    {% usemacro my_macro "foo" "bar" baz="KW" %}
    <br>
    {% usemacro my_macro num_pages "bar" %}

  Renders like::

    foo bar KW
    77 bar Default baz

4) Alternatively save your macros in a separate file, e.g. "mymacro.html" and load it to the current template with::

        {% loadmacros "mymacros.html" %}

    Then use these loaded macros in as described above.

Bear in mind that defined and loaded macros are local to each template
file and are not inherited through `{% extends ... %}` tags.

5) When recursive macros are needed, use the 'recurse_macro' template tag::

    {% macro MENU entries %}
    <ul>
        {% for entry in entries %}
        <li>
            <a href="{{ entry.link }}"> {{ entry.label }} </a>
            {% if entry.children %}
                {% recurse_macro MENU entry.children %}
            {% endif %}
        </li>
        {% endfor %}
    </ul>
    {% endmacro %}
    {% usemacro MENU menu.children %}


.. |PyPI Version| image:: https://img.shields.io/pypi/v/django-templates-macros.svg
   :target: https://pypi.python.org/pypi/django-templates-macros

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/twidi/django-templates-macros",
    "name": "django-templates-macros",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Stephane \"Twidi\" Angel",
    "author_email": "s.angel@twidi.com",
    "download_url": "https://files.pythonhosted.org/packages/c7/5c/41cfe5b1a49df4f9b64fb9ca9aac4362faa079665af5bfaf399985f09eac/django-templates-macros-0.3.tar.gz",
    "platform": null,
    "description": "|PyPI Version|\n\ndjango-templates-macros\n=======================\n\nAdd macros to your django templates\n\n------\nOrigin\n------\n\nThe original code of this app is taken from https://djangosnippets.org/snippets/2892/ by MattP.\n\nThis snippets cites::\n\n    Based on snippet by\n        Michal Ludvig <michal@logix.cz> http://www.logix.cz/michal\n        http://djangosnippets.org/snippets/363/\n\n    Extended for args and kwargs into templatetags/kwacro.py by\n        Skylar Saveland <michal@logix.cz> http://skyl.org\n        https://gist.github.com/skyl/1715202\n\n    Modified to support rendering into context by matt@peloquin.com\n\n\n-----\nWhere\n-----\n\nYou can find this package here:\n\n- Github repository: https://github.com/twidi/django-templates-macros\n- Pypi package: https://pypi.python.org/pypi/django-templates-macros\n\n\n-----\nUsage\n-----\n\n0) Add this app \"macros\" to your INSTALLED_APPS\n\n1) In your template load the library::\n\n    {% load macros %}\n\n2) Define a new macro called 'my_macro' that takes args and/or kwargs\n   All will be optional::\n\n    {% macro my_macro arg1 arg2 baz=\"Default baz\" %}\n        {% firstof arg1 \"default_arg1\" %}\n        {% if arg2 %}{{ arg2 }}{% else %}default_arg2{% endif %}\n        {{ baz }}\n    {% endmacro %}\n\n3) Use the macro with string parameters or context variables::\n\n    {% usemacro my_macro \"foo\" \"bar\" baz=\"KW\" %}\n    <br>\n    {% usemacro my_macro num_pages \"bar\" %}\n\n  Renders like::\n\n    foo bar KW\n    77 bar Default baz\n\n4) Alternatively save your macros in a separate file, e.g. \"mymacro.html\" and load it to the current template with::\n\n        {% loadmacros \"mymacros.html\" %}\n\n    Then use these loaded macros in as described above.\n\nBear in mind that defined and loaded macros are local to each template\nfile and are not inherited through `{% extends ... %}` tags.\n\n5) When recursive macros are needed, use the 'recurse_macro' template tag::\n\n    {% macro MENU entries %}\n    <ul>\n        {% for entry in entries %}\n        <li>\n            <a href=\"{{ entry.link }}\"> {{ entry.label }} </a>\n            {% if entry.children %}\n                {% recurse_macro MENU entry.children %}\n            {% endif %}\n        </li>\n        {% endfor %}\n    </ul>\n    {% endmacro %}\n    {% usemacro MENU menu.children %}\n\n\n.. |PyPI Version| image:: https://img.shields.io/pypi/v/django-templates-macros.svg\n   :target: https://pypi.python.org/pypi/django-templates-macros\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Add macros to your django templates",
    "version": "0.3",
    "project_urls": {
        "Homepage": "https://github.com/twidi/django-templates-macros"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d9a6248cc57d4717e2bf9c9ff36d745a14da7d42d16099a60d22a590c2552607",
                "md5": "fd08b9fdc66f6328212b03c1b2c0934a",
                "sha256": "aadee18b13086c98860a870716f4c0b134eeadb4f89f626ef074e1872ff41ea7"
            },
            "downloads": -1,
            "filename": "django_templates_macros-0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fd08b9fdc66f6328212b03c1b2c0934a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5686,
            "upload_time": "2023-08-16T23:31:52",
            "upload_time_iso_8601": "2023-08-16T23:31:52.049315Z",
            "url": "https://files.pythonhosted.org/packages/d9/a6/248cc57d4717e2bf9c9ff36d745a14da7d42d16099a60d22a590c2552607/django_templates_macros-0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c75c41cfe5b1a49df4f9b64fb9ca9aac4362faa079665af5bfaf399985f09eac",
                "md5": "72f4026561fe90b3bdb82b51ae877e1e",
                "sha256": "d67e05b014201b8512eec2e106a9341a49e7691b7b83e6679b40ee9630a2e80e"
            },
            "downloads": -1,
            "filename": "django-templates-macros-0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "72f4026561fe90b3bdb82b51ae877e1e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5081,
            "upload_time": "2023-08-16T23:31:53",
            "upload_time_iso_8601": "2023-08-16T23:31:53.667409Z",
            "url": "https://files.pythonhosted.org/packages/c7/5c/41cfe5b1a49df4f9b64fb9ca9aac4362faa079665af5bfaf399985f09eac/django-templates-macros-0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-16 23:31:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "twidi",
    "github_project": "django-templates-macros",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-templates-macros"
}
        
Elapsed time: 0.31993s