{"id":23440776,"url":"https://github.com/dabapps/django-wrapwith","last_synced_at":"2025-04-13T09:13:00.552Z","repository":{"id":45565800,"uuid":"240484786","full_name":"dabapps/django-wrapwith","owner":"dabapps","description":"A Django template tag for wrapping a template block in a reusable enclosing template","archived":false,"fork":false,"pushed_at":"2024-03-20T16:42:27.000Z","size":30,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-06T11:47:12.345Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dabapps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-14T10:37:15.000Z","updated_at":"2023-11-07T19:52:25.000Z","dependencies_parsed_at":"2023-02-12T12:50:20.282Z","dependency_job_id":null,"html_url":"https://github.com/dabapps/django-wrapwith","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabapps%2Fdjango-wrapwith","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabapps%2Fdjango-wrapwith/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabapps%2Fdjango-wrapwith/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabapps%2Fdjango-wrapwith/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dabapps","download_url":"https://codeload.github.com/dabapps/django-wrapwith/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681475,"owners_count":21144698,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-23T16:18:36.249Z","updated_at":"2025-04-13T09:13:00.526Z","avatar_url":"https://github.com/dabapps.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"django-wrapwith\n===============\n\n**A Django template tag for wrapping a template block in a reusable enclosing template.**\n\nProvides a block tag called `wrapwith` which behaves exactly like [the built-in `include` tag](https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#include), but injects the contents of the block into the included template.\n\nIt is intended to make wrapper markup reusable, encouraging you to break your template into \"components\" which might have a particular enclosing structure but varying contents. It is particularly useful with design systems that provide components (cards, blockquotes, accordians etc) that have reusable structure but arbitrary content.\n\nA toy example: imagine your design includes a box component which has a coloured border, but can contain any other markup inside it.\n\nFirst, create a wrapper template, `wrappers/box.html`:\n\n```html\n\u003cdiv style=\"border: 1px solid {{ bordercol }}\"\u003e\n  {{ wrapped }}\n\u003c/div\u003e\n```\n\nNote the special `{{ wrapped }}` variable, which will be replaced with your wrapped content.\n\nThen, in your main page template:\n\n```html\n{% load wrapwith %}\n\n\u003chtml\u003e\n  \u003cbody\u003e\n    \u003ch1\u003ewelcome to my page\u003c/h1\u003e\n\n    {% wrapwith \"wrappers/box.html\" with bordercol=\"red\" %}\n      \u003cp\u003ethis is inside a red box\u003c/p\u003e\n    {% endwrapwith %}\n\n    {% wrapwith \"wrappers/box.html\" with bordercol=\"green\" %}\n      \u003cp\u003ethis is inside a green box\u003c/p\u003e\n      \u003cp\u003eand here's another paragraph inside the green box\u003c/p\u003e\n    {% endwrapwith %}\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Optional: aliasing templates\n\nIf you find writing out the full template path every time you use a component too verbose, you can define a dictionary of \"aliases\" in your Django settings, using the setting name `WRAPWITH_TEMPLATES`. This dictionary can be nested. You can then use a dotted path into this dictionary in your templates.\n\nIn your `settings.py`:\n\n```python\nWRAPWITH_TEMPLATES = {\n  \"wrappers\": {\n    \"box\": \"wrappers/box.html\",\n  },\n}\n```\n\nIn your template:\n\n```html\n{% wrapwith wrappers.box with bordercol=\"red\" %}\n  \u003cp\u003ethis is inside a red box\u003c/p\u003e\n{% endwrapwith %}\n```\n\nTested on Python 3 with all currently supported Django versions.\n\n## Installation\n\n    pip install django-wrapwith\n\nThen add `wrapwith` to your `INSTALLED_APPS`.\n\n## Code of conduct\n\nFor guidelines regarding the code of conduct when contributing to this repository please review https://www.dabapps.com/open-source/code-of-conduct/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabapps%2Fdjango-wrapwith","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdabapps%2Fdjango-wrapwith","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabapps%2Fdjango-wrapwith/lists"}