Feature request: Template tag like stateless component in JSX React

105 views
Skip to first unread message

Aztec Rabbit

unread,
Jan 28, 2021, 8:33:34 AM1/28/21
to Django developers (Contributions to Django itself)
Hi,

I think template tag like in JSX is very useful, for example:

> card.html

<div>
  <h1>{{ title }}</h1>
  <p>{{ component.children }}</p>
</div>

> index.html

{% component './card.html' with title='Foo' %}
  Bar
{% endcomponent %}

Jure Erznožnik

unread,
Jan 28, 2021, 9:34:03 AM1/28/21
to django-d...@googlegroups.com

We have just created a tag like that in our dynamicforms library. It's called "extendtemplateblock". Feel free to use or copy, but it doesn't look like it's going to be accepted in Django itself.

We tried to keep API similar to the "include" tag, so it should be easy to use.

You can choose to only pull one block from your extended template ("block" parameter) or define any of the blocks in it using "block" nested blocks.

LP,
Jure

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ff75ddef-2267-44f5-89f7-9b8ebf1460efn%40googlegroups.com.

Aztec Rabbit

unread,
Jan 28, 2021, 12:52:27 PM1/28/21
to Django developers (Contributions to Django itself)
Is there a link to the documentation or source code to the library you created? And can i know why it is not accepted?

Curtis Maloney

unread,
Jan 28, 2021, 3:28:29 PM1/28/21
to 'Mike Hansen' via Django developers (Contributions to Django itself)

--
C

Jure Erznožnik

unread,
Jan 28, 2021, 11:27:26 PM1/28/21
to django-d...@googlegroups.com
Source is here (https://github.com/velis74/DynamicForms/blob/master/dynamicforms/templatetags/dynamicforms.py
- see at end of file), documentation will follow shortly as we near
1.0 release (right now it's pretty pathetic, but it is there at
readthedocs), but there are examples & unit tests included showing
most of the functionality.

As far as I understood the feature wasn't perceived as something that
would improve Django as a whole. There is that thing we need to be
wary of - feature creep. Generally added features are preferred to be
provided as third party libraries. Easier to maintain, easier to find
that exact match you're looking for. Just look: Curtis also pointed
you to his own version, a bit different that ours, but maybe it would
suit you more?

LP,
Jure
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/0cb2a1f6-9070-4875-90e2-eb6da241ea82n%40googlegroups.com.

Aztec Rabbit

unread,
Jan 29, 2021, 3:18:25 AM1/29/21
to Django developers (Contributions to Django itself)
Curtis - This is nested block right? what i want is like tag include (can be called more than once) but with children.

Jure - I've read the documentation, can you give me a sample code? I am confused

Hmmm, but i think this feature is very useful (for card, container, wrapper, and anythink with different content) and each component can be included in other components, thats awesome. I think this feature should be in django core, but, yes, I understand.

Jure Erznožnik

unread,
Jan 29, 2021, 3:24:50 AM1/29/21
to django-d...@googlegroups.com

Aztec,

Just look in the dynamicforms/templates folder: all templates for input fields are built using this tag in its various forms. There's plenty of examples there. And yes, it's exactly what you asked for.

LP,
Jure

Curtis Maloney

unread,
Jan 29, 2021, 3:05:50 PM1/29/21
to 'Mike Hansen' via Django developers (Contributions to Django itself)
On Fri, 29 Jan 2021, at 19:18, Aztec Rabbit wrote:
Curtis - This is nested block right? what i want is like tag include (can be called more than once) but with children.

Correct. And that's more or less what nested block does;

The difference from include is sniplates takes a template and rips the blocks from it, each of which then becomes a macro of sorts.


Jure - I've read the documentation, can you give me a sample code? I am confused

Hmmm, but i think this feature is very useful (for card, container, wrapper, and anythink with different content) and each component can be included in other components, thats awesome. I think this feature should be in django core, but, yes, I understand.

I agree that it could be quite useful.

I would suggest first making a sample implementation. This would involve taking `do_include` from django/templates/loader_tags.py and making a version that's an enclosing block tag (like block)... then exposing the nodelist in the context.

--
Curtis

Reply all
Reply to author
Forward
0 new messages