clokep / django-render-block

Render the content of a specific block tag from a Django template.
ISC License
241 stars 23 forks source link

Utilize Django Template Loaders #49

Open geoffrey-eisenbarth opened 9 months ago

geoffrey-eisenbarth commented 9 months ago

I'm not sure if you're aware of a similar project, django-template-partials, which allows users to render partial templates by simply appending the partial name to the template name, e.g. template_name = 'my_template.html#my-partial-name' within a TemplateResponse class-based view. I don't know the specifics of their approach (yet?), but it seems to hook into Django's Template Loaders, and if a given template name contains a #, it splits it and renders the request partial (or block, in your case).

That library does not seem to support template inheritance the way yours does (e.g., with django-render-block I can render a block defined in a parent template, but with django-template-partials it's not possible to render a partial defined in a parent template).

I'd love to be able to use a similar shorthand with your library instead of having to import and call render_block_to_string in each of the response generating methods of a given ClassBaseView.

clokep commented 9 months ago

django-template-partials, which allows users to render partial templates by simply appending the partial name to the template name

I am aware of this and found it intriguing, but haven't had time to look into how they are doing it! It seems like a useful feature to support.