-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rendering components from views #18
Comments
Hey @mixxorz, I was testing the same thing this morning as the stack I'm working on is django with htmx. # inventory/views.py
class IOHistoryList(generic.ListView):
model = IOHistory
slug_field = 'code'
template_name = 'ui/inventory/IOHistory.html' # <-- this is a slipper component
def get_queryset(self):
queryset = super().get_queryset()
return queryset.filter(
product__code=self.kwargs.get('code')
) # ui/templates/IOHistory.html
<h3 class="text-md font-bold pb-4">IO History</h3>
<table class="table-auto">
<tbody>
{% for history in object_list %}
<tr>
<td>{{ history.date|date:'Y/m/d' }}</td>
<td class="pl-5 text-green-60">
{% if history.quantity_in %}
<strong>↓{{ history.quantity_in }}</strong>
{% else %}
<strong>---</strong>
{% endif %}
</td>
<td class="pl-3 text-red-60">
{% if history.quantity_out %}
<strong>↑{{ history.quantity_out }}</strong>
{% else %}
<strong>---</strong>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table> # templates/inventory/product_detail.html
....
{% fragment as ioHistory %}
<div hx-get="{% url 'inventory:io-history' product.code %}" hx-trigger="load"></div>
{% endfragment %}
{% Card header=cardHeader content=ioHistory %} And also the "htmx" response from my slipper component And I think that works just fine because the slipper component it's nothing different than a Django template, the only scenario where this may not work is if you're not rendering the template in your views, but would appreciate if you could include the error you faced bc I'm deciding to use slipper on a mid-size project here and would be great to know any possible issues in advance o/ |
It may be useful to render components from views. I came across this while trying to use slippers components with HTMX.
The text was updated successfully, but these errors were encountered: