mirror of
https://github.com/django-components/django-components.git
synced 2025-08-10 09:17:59 +00:00
Bug : Relative path in extends
and include
does not work when using template_file (#976)
Co-authored-by: Juro Oravec <juraj.oravec.josefson@gmail.com>
This commit is contained in:
parent
3cf586a974
commit
58d4c78671
3 changed files with 64 additions and 1 deletions
|
@ -737,7 +737,10 @@ class Component(
|
|||
template: Template = cached_template(
|
||||
template_string=template_body,
|
||||
name=self.template_file or self.name,
|
||||
origin=Origin(name=self.template_file or get_import_path(self.__class__)),
|
||||
origin=Origin(
|
||||
name=self.template_file or get_import_path(self.__class__),
|
||||
template_name=self.template_file or self.name,
|
||||
),
|
||||
)
|
||||
else:
|
||||
template = template_body
|
||||
|
|
5
tests/templates/relative_extends.html
Normal file
5
tests/templates/relative_extends.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
{% extends './block.html' %}
|
||||
|
||||
{% block body %}
|
||||
BLOCK OVERRIDEN
|
||||
{% endblock %}
|
|
@ -18,6 +18,15 @@ class BlockedAndSlottedComponent(Component):
|
|||
template_file = "blocked_and_slotted_template.html"
|
||||
|
||||
|
||||
class RelativeFileComponentUsingTemplateFile(Component):
|
||||
template_file = "relative_extends.html"
|
||||
|
||||
|
||||
class RelativeFileComponentUsingGetTemplateName(Component):
|
||||
def get_template_name(self, context):
|
||||
return "relative_extends.html"
|
||||
|
||||
|
||||
#######################
|
||||
# TESTS
|
||||
#######################
|
||||
|
@ -836,3 +845,49 @@ class ExtendsCompatTests(BaseTestCase):
|
|||
</html>
|
||||
"""
|
||||
self.assertHTMLEqual(rendered, expected)
|
||||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_component_using_template_file_extends_relative_file(self):
|
||||
registry.register("relative_file_component_using_template_file", RelativeFileComponentUsingTemplateFile)
|
||||
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
{% component "relative_file_component_using_template_file" %}{% endcomponent %}
|
||||
"""
|
||||
rendered = Template(template).render(Context())
|
||||
expected = """
|
||||
<!DOCTYPE html>
|
||||
<html data-djc-id-a1bc3f="" lang="en">
|
||||
<body>
|
||||
<main role="main">
|
||||
<div class='container main-container'>
|
||||
BLOCK OVERRIDEN
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
self.assertHTMLEqual(rendered, expected)
|
||||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_component_using_get_template_name_extends_relative_file(self):
|
||||
registry.register("relative_file_component_using_get_template_name", RelativeFileComponentUsingGetTemplateName)
|
||||
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
{% component "relative_file_component_using_get_template_name" %}{% endcomponent %}
|
||||
"""
|
||||
rendered = Template(template).render(Context())
|
||||
expected = """
|
||||
<!DOCTYPE html>
|
||||
<html data-djc-id-a1bc3f="" lang="en">
|
||||
<body>
|
||||
<main role="main">
|
||||
<div class='container main-container'>
|
||||
BLOCK OVERRIDEN
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
self.assertHTMLEqual(rendered, expected)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue