tetra-framework / tetra

Tetra - A full stack component framework for Django using Alpine.js
https://www.tetraframework.com
MIT License
540 stars 14 forks source link

Components should support "if blocks.foo" statements #45

Closed nerdoc closed 3 months ago

nerdoc commented 3 months ago

Proposed as idea in https://github.com/samwillis/tetra/discussions/44

Originally posted by **nerdoc** March 27, 2024, adapted a bit Many times, in components you need to render some tags depending on a block being present or not, especially in "easy" BasicComponents: E.g. In a Bootstrap card, if there is a title, I want to render a card-header > card-title div, and inside, the block with the title: ```django {% if blocks.title or blocks.actions %}

{% block title %}{% endblock %}

{% block actions %}{% endblock %}
{% endif %} ``` If there is **no** title or actions block, the whole header is not rendered, which adds much flexibility to Tetra components. Tetra can't do that yet. But Tetra components could support a `blocks` variable that just has booleans as members, named after the available blocks. So you could use `{% if blocks.title %}
{% block title %}
{% endif %}` This would ease creating components a lot.