diff --git a/README.md b/README.md index 14cd6c67..62a972ec 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A way to create simple reusable template components in Django. It lets you create "template components", that contains both the template, the Javascript and the CSS needed to generate the front end code you need for a modern app. Components look like this: ```htmldjango -{% component "calendar" date="2015-06-19" %} +{% component_block "calendar" date="2015-06-19" %}{% endcomponent_block %} ``` And this is what gets rendered (plus the CSS and Javascript you've specified): @@ -220,7 +220,7 @@ First load the `component_tags` tag library, then use the `component_[js/css]_de {% component_css_dependencies %} - {% component "calendar" date="2015-06-19" %} + {% component_block "calendar" date="2015-06-19" %}{% endcomponent_block %} {% component_js_dependencies %} @@ -614,10 +614,10 @@ COMPONENTS = { ## Component context and scope -By default, components can access context variables from the parent template, just like templates that are included with the `{% include %}` tag. Just like with `{% include %}`, if you don't want the component template to have access to the parent context, add `only` to the end of the `{% component %}` (or `{% component_block %}` tag): +By default, components can access context variables from the parent template, just like templates that are included with the `{% include %}` tag. Just like with `{% include %}`, if you don't want the component template to have access to the parent context, add `only` to the end of the `{% component_block %}` (or `{% component_block %}{% endcomponent_block %}` tag): ```htmldjango - {% component "calendar" date="2015-06-19" only %} + {% component_block "calendar" date="2015-06-19" only %}{% endcomponent_block %} ``` NOTE: `{% csrf_token %}` tags need access to the top-level context, and they will not function properly if they are rendered in a component that is called with the `only` modifier. diff --git a/benchmarks/component_rendering.py b/benchmarks/component_rendering.py index 2807e562..cdd5c009 100644 --- a/benchmarks/component_rendering.py +++ b/benchmarks/component_rendering.py @@ -92,7 +92,7 @@ class RenderBenchmarks(SimpleTestCase): def test_render_time_for_small_component(self): template = Template( "{% load component_tags %}{% component_block 'test_component' %}" - "{% slot \"header\" %}{% component 'inner_component' variable='foo' %}{% endslot %}" + "{% slot \"header\" %}{% component_block 'inner_component' variable='foo' %}{% endslot %}{% endcomponent_block %}" "{% endcomponent_block %}", name="root", ) @@ -105,7 +105,7 @@ class RenderBenchmarks(SimpleTestCase): template = Template( "{% load component_tags %}{% component_dependencies %}" "{% component_block 'test_component' %}{% slot \"header\" %}" - "{% component 'inner_component' variable='foo' %}{% endslot %}{% endcomponent_block %}", + "{% component_block 'inner_component' variable='foo' %}{% endslot %}{% endcomponent_block %}{% endcomponent_block %}", name="root", ) # Sanity tests diff --git a/django_components/component.py b/django_components/component.py index 40d0fafe..0bbf905d 100644 --- a/django_components/component.py +++ b/django_components/component.py @@ -253,7 +253,7 @@ class Component(View, metaclass=SimplifiedInterfaceMediaDefiningClass): # can be invoked with implicit filling. if default_fill_content and not default_slot_encountered: raise TemplateSyntaxError( - f"Component '{self.registered_name}' passed default fill content " + f"Component '{self.registered_name}' passed default fill content '{default_fill_content}'" f"(i.e. without explicit 'fill' tag), " f"even though none of its slots is marked as 'default'." ) diff --git a/django_components/templatetags/component_tags.py b/django_components/templatetags/component_tags.py index ec795fb2..073e21ad 100644 --- a/django_components/templatetags/component_tags.py +++ b/django_components/templatetags/component_tags.py @@ -151,23 +151,6 @@ def component_js_dependencies_tag(preload=""): return mark_safe("\n".join(rendered_dependencies)) - -@register.tag(name="component") -def do_component(parser, token): - bits = token.split_contents() - bits, isolated_context = check_for_isolated_context_keyword(bits) - - component_name, context_args, context_kwargs = parse_component_with_args( - parser, bits, "component" - ) - return ComponentNode( - FilterExpression(component_name, parser), - context_args, - context_kwargs, - isolated_context=isolated_context, - ) - - class UserSlotVar: """ Extensible mechanism for offering 'fill' blocks in template access to properties diff --git a/sampleproject/calendarapp/templates/calendarapp/calendar.html b/sampleproject/calendarapp/templates/calendarapp/calendar.html index 91a5683e..970fab1c 100644 --- a/sampleproject/calendarapp/templates/calendarapp/calendar.html +++ b/sampleproject/calendarapp/templates/calendarapp/calendar.html @@ -5,7 +5,7 @@ {% component_css_dependencies %} - {% component "calendar" date=date %} + {% component_block "calendar" date=date %}{% endcomponent_block %} {% component_block "greeting" name='Joe' %} {% fill "message" %} Howdy? diff --git a/tests/templates/mdn_complete_page.html b/tests/templates/mdn_complete_page.html index cb9cefa2..35893257 100644 --- a/tests/templates/mdn_complete_page.html +++ b/tests/templates/mdn_complete_page.html @@ -200,7 +200,7 @@ Page lightly modified and partially extracted as a component #}

Document and website structure

- {% component 'breadcrumb_component' items=5 %} + {% component_block 'breadcrumb_component' items=5 %}{% endcomponent_block %}