{"id":16507541,"url":"https://github.com/chmp/template-fragments-py","last_synced_at":"2026-06-02T21:32:01.052Z","repository":{"id":174467167,"uuid":"556381480","full_name":"chmp/template-fragments-py","owner":"chmp","description":"Template fragments for jinja-like engines","archived":false,"fork":false,"pushed_at":"2023-06-11T17:10:34.000Z","size":30,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-28T03:17:00.462Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chmp.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-23T18:18:04.000Z","updated_at":"2024-02-13T11:46:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"681733e3-2e1c-4b43-8f85-4237cd9eeda8","html_url":"https://github.com/chmp/template-fragments-py","commit_stats":null,"previous_names":["chmp/template-fragments-py"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/chmp/template-fragments-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chmp%2Ftemplate-fragments-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chmp%2Ftemplate-fragments-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chmp%2Ftemplate-fragments-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chmp%2Ftemplate-fragments-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chmp","download_url":"https://codeload.github.com/chmp/template-fragments-py/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chmp%2Ftemplate-fragments-py/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33838215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-02T02:00:07.132Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-11T15:28:41.929Z","updated_at":"2026-06-02T21:32:01.038Z","avatar_url":"https://github.com/chmp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Template fragments for jinja-like engines\r\n\r\n[API reference](#api-reference)\r\n| [License](#license)\r\n\r\nUsage:\r\n\r\n```python\r\nfrom template_fragments import filter_template\r\n\r\ntemplate_source = \"\"\"\r\n\u003chtml\u003e\r\n    \u003chead\u003e\r\n        \u003ctitle\u003eExample\u003c/title\u003e\r\n    \u003c/head\u003e\r\n    \u003cbody\u003e\r\n        \u003cdiv\u003e\r\n        {% fragment content %}\r\n            \u003c!-- content here --\u003e\r\n        {% endfragment %}\r\n        \u003c/div\u003e\r\n    \u003c/body\u003e\r\n\u003c/html\u003e\r\n\"\"\"\r\n\r\ncontent_full = filter_template(template_source, \"\")\r\ncontent_item = filter_template(template_source, \"item\")\r\n```\r\n\r\nUsage with [Flask][flask] and [Jinja2][jinja2]:\r\n\r\n```python\r\nfrom template_fragments.jinja import FragmentLoader\r\n\r\napp.jinja_loader = FragmentLoader(app.jinja_loader)\r\n\r\n\r\n@app.route(\"/\")\r\ndef get_index():\r\n    return render_template(\"index.html\", ...)\r\n\r\n\r\n@app.route(\"/item/\u003citem\u003e\")\r\ndef get_item(item):\r\n    return render_template(\"index.html#item\", ...)\r\n```\r\n\r\n## API reference\r\n\r\n\u003c!-- minidoc \"module\": \"template_fragments\", \"header\": false --\u003e\r\n\r\n### `template_fragments.split_templates`\r\n\r\n[template_fragments.split_templates]: #template_fragmentssplit_templates\r\n\r\n`template_fragments.split_templates(src: str) -\u003e Dict[str, str]`\r\n\r\nReturn all fragments contained in the template\r\n\r\nThe key `\"\"` gives the source template with any fragment directives removed.\r\n\r\n### `template_fragments.filter_template`\r\n\r\n[template_fragments.filter_template]: #template_fragmentsfilter_template\r\n\r\n`template_fragments.filter_template(src: str, fragment: str = '') -\u003e str`\r\n\r\nReturn the parts of the template for the given fragment\r\n\r\nParameters:\r\n\r\n- `src`: the template source\r\n- `fragment`: the fragment to return. If `fragment = \"\"`, removes any\r\n  fragment directives\r\n\r\n### `template_fragments.split_path`\r\n\r\n[template_fragments.split_path]: #template_fragmentssplit_path\r\n\r\n`template_fragments.split_path(path: str) -\u003e Tuple[str, str]`\r\n\r\nSplit the fragment from the path\r\n\r\n### `template_fragments.TemplateFragmentError`\r\n\r\n[template_fragments.TemplateFragmentError]: #template_fragmentstemplatefragmenterror\r\n\r\n`template_fragments.TemplateFragmentError`\r\n\r\nCommon base class for all non-exit exceptions.\r\n\r\n\u003c!-- minidoc --\u003e\r\n\r\n### `template_fragments.jinja`\r\n\r\n\u003c!-- minidoc \"module\": \"template_fragments.jinja\", \"header\": false --\u003e\r\nJinja specific helpers\r\n\r\n#### `template_fragments.jinja.FragmentLoader`\r\n\r\n[template_fragments.jinja.FragmentLoader]: #template_fragmentsjinjafragmentloader\r\n\r\n`template_fragments.jinja.FragmentLoader(base_loader: jinja2.loaders.BaseLoader)`\r\n\r\nA loader that filters fragments\r\n\r\n\u003c!-- minidoc --\u003e\r\n\r\n\r\n## License\r\n\r\n```\r\nThe MIT License (MIT)\r\nCopyright (c) 2022 - 2023 Christopher Prohm\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a\r\ncopy of this software and associated documentation files (the \"Software\"),\r\nto deal in the Software without restriction, including without limitation\r\nthe rights to use, copy, modify, merge, publish, distribute, sublicense,\r\nand/or sell copies of the Software, and to permit persons to whom the\r\nSoftware is furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in\r\nall copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r\nDEALINGS IN THE SOFTWARE.\r\n```\r\n\r\n[flask]: https://flask.palletsprojects.com/\r\n[jinja2]: https://jinja.palletsprojects.com/\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchmp%2Ftemplate-fragments-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchmp%2Ftemplate-fragments-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchmp%2Ftemplate-fragments-py/lists"}